Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] After upgrading to Prisma 8, the Repository class does not have the Prisma object injected. #2927

Closed
vangie opened this issue Dec 9, 2024 · 7 comments · Fixed by #2929
Assignees

Comments

@vangie
Copy link
Contributor

vangie commented Dec 9, 2024

Describe the bug

file:///Users/duwan/Workspaces/babelcloud/babel-agent/node_modules/.pnpm/@[email protected]_@[email protected][email protected]__@[email protected]_@[email protected]_@tsed+c_ij6f7ml4xn5ow446coa3uzrxzy/node_modules/@tsed/prisma/lib/.schema/repositories/JobsRepository.js:18
        return this.prisma.job;
                           ^

TypeError: Cannot read properties of undefined (reading 'job')
    at get collection [as collection] (file:///Users/duwan/Workspaces/babelcloud/babel-agent/node_modules/.pnpm/@[email protected]_@[email protected][email protected]__@[email protected]_@[email protected]_@tsed+c_ij6f7ml4xn5ow446coa3uzrxzy/node_modules/@tsed/prisma/lib/.schema/repositories/JobsRepository.js:18:28)

To Reproduce

  1. prisma:8.3.0 @prisma/client:6.0.1 prisma:6.0.1
  2. npx prisma migrate deploy is sucess
  3. Invoke any generated Repository after started my project, I encountered the above error.

Expected behavior

it works,before upgraded to tsed 8, I have already made upgrade adjustments according to this document https://tsed.dev/introduction/migrate-from-v7.html

Code snippets

@tsed/prisma/lib/.schema/repositories/JobsRepository.js

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { isArray } from "@tsed/core";
import { deserialize } from "@tsed/json-mapper";
import { Injectable, Inject } from "@tsed/di";
import { PrismaService } from "../services/PrismaService.js";
import { JobModel } from "../models/index.js";
let JobsRepository = class JobsRepository {
    prisma;
    get collection() {
        return this.prisma.job;
    }
    get groupBy() {
        return this.collection.groupBy.bind(this.collection);
    }
    deserialize(obj) {
        return deserialize(obj, { type: JobModel, collectionType: isArray(obj) ? Array : undefined });
    }
    async findUnique(args) {
        const obj = await this.collection.findUnique(args);
        return this.deserialize(obj);
    }
    async findFirst(args) {
        const obj = await this.collection.findFirst(args);
        return this.deserialize(obj);
    }
    async findMany(args) {
        const obj = await this.collection.findMany(args);
        return this.deserialize(obj);
    }
    async create(args) {
        const obj = await this.collection.create(args);
        return this.deserialize(obj);
    }
    async update(args) {
        const obj = await this.collection.update(args);
        return this.deserialize(obj);
    }
    async upsert(args) {
        const obj = await this.collection.upsert(args);
        return this.deserialize(obj);
    }
    async delete(args) {
        const obj = await this.collection.delete(args);
        return this.deserialize(obj);
    }
    deleteMany(args) {
        return this.collection.deleteMany(args);
    }
    updateMany(args) {
        return this.collection.updateMany(args);
    }
    aggregate(args) {
        return this.collection.aggregate(args);
    }
};
__decorate([
    Inject(),
    __metadata("design:type", PrismaService)
], JobsRepository.prototype, "prisma", void 0);
JobsRepository = __decorate([
    Injectable()
], JobsRepository);
export { JobsRepository };

schema.prisma

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["postgresqlExtensions"]
}

generator tsed {
  provider           = "tsed-prisma-esm"
  emitTranspiledCode = true
}

datasource db {
  provider   = "postgresql"
  url        = env("DATABASE_URL")
  extensions = [vector, pgcrypto]
}

I tried changing the provider value to tsed-prisma, but the same error occurred.

Repository URL example

No response

OS

macOS

Node version

Node v20.11.1

Library version

v8.3.0

Additional context

No response

Copy link

github-actions bot commented Dec 9, 2024

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

1 similar comment
Copy link

github-actions bot commented Dec 9, 2024

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

@Romakita
Copy link
Collaborator

Romakita commented Dec 9, 2024

🎉 This issue has been resolved in version 8.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@vangie
Copy link
Contributor Author

vangie commented Dec 9, 2024

same error after upgrade to v8.3.1

file:///Users/duwan/Workspaces/babelcloud/babel-agent/node_modules/.pnpm/@[email protected]_@[email protected][email protected]__@[email protected]_@[email protected]_@tsed+c_xljld2z7djwywtcmqkdse5eplu/node_modules/@tsed/prisma/lib/.schema/repositories/JobsRepository.js:18
        return this.prisma.job;
                           ^

TypeError: Cannot read properties of undefined (reading 'job')
    at get collection [as collection] (file:///Users/duwan/Workspaces/babelcloud/babel-agent/node_modules/.pnpm/@[email protected]_@[email protected][email protected]__@[email protected]_@[email protected]_@tsed+c_xljld2z7djwywtcmqkdse5eplu/node_modules/@tsed/prisma/lib/.schema/repositories/JobsRepository.js:18:28)

The error occurs when calling the Repository after the service starts, not during the generation process.

@Romakita
Copy link
Collaborator

Romakita commented Dec 9, 2024

Ok. It appears the problem doesn't occurs when we use output option:

generator tsed {
  provider = "tsed-prisma"
  output   = "../src/__generated__"
}

Romakita pushed a commit that referenced this issue Dec 9, 2024
Romakita pushed a commit that referenced this issue Dec 9, 2024
Romakita pushed a commit that referenced this issue Dec 9, 2024
@Romakita
Copy link
Collaborator

Romakita commented Dec 9, 2024

Fix is on going ;)

@Romakita
Copy link
Collaborator

Romakita commented Dec 9, 2024

🎉 This issue has been resolved in version 8.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants