prisma: 4.16: (MongoDB) Generated types for list composites are incorrect
Bug description
Reading the 4.16 patch notes I don’t see any communication about changes on MongoDB types but we experienced them.
Model
model LegacyInterfaceOperation {
idOperation String @id @default(auto()) @map("_id") @db.ObjectId
operationType OperationType
fileType FileType
status OperationStatus
previous OperationStatus?
next OperationStatus?
fromDate DateTime?
idInstitution Int
interfacing Int
fileName String
fileUrl String?
parentDir String?
recordCount Int @default(0)
retries Int @default(0)
error String?
report Json?
createdAt DateTime? @default(now())
updatedAt DateTime? @updatedAt
metadata OperationMetadata?
@@map("legacyInterfaceOperation")
@@index(idInstitution)
}
Type generated using 4.15
export type LegacyInterfaceOperation = {
idOperation: string
operationType: OperationType
fileType: FileType
status: OperationStatus
previous: OperationStatus | null
next: OperationStatus | null
fromDate: Date | null
idInstitution: number
interfacing: number
fileName: string
fileUrl: string | null
parentDir: string | null
recordCount: number
retries: number
error: string | null
report: Prisma.JsonValue | null
createdAt: Date | null
updatedAt: Date | null
metadata: OperationMetadata | null
}
How to reproduce
- Update to 4.16
- Generate Prisma Client
- Observe new types
export type LegacyInterfaceOperation = runtime.Types.DefaultSelection<LegacyInterfaceOperationPayload>
export type LegacyInterfaceOperationPayload<ExtArgs extends $Extensions.Args = $Extensions.DefaultArgs> = {
objects: {}
scalars: $Extensions.GetResult<{
idOperation: string
operationType: OperationType
fileType: FileType
status: OperationStatus
previous: OperationStatus | null
next: OperationStatus | null
fromDate: Date | null
idInstitution: number
interfacing: number
fileName: string
fileUrl: string | null
parentDir: string | null
recordCount: number
retries: number
error: string | null
report: Prisma.JsonValue | null
createdAt: Date | null
updatedAt: Date | null
}, ExtArgs["result"]["legacyInterfaceOperation"]>
composites: {
metadata: OperationMetadataPayload | null
}
}
Expected behavior
Can we get any insights on the change, or a migration guide? We were using the convient types from Prisma in some place of our apps but now there are new fields and such and I’m not sure the underlying behavior changed.
Prisma information
See the model at the start of the issue.
Environment & setup
- OS: MacOs
- Database: MongoDB
- Node.js version: 18.16
Prisma Version
Environment variables loaded from .env
prisma : 4.16.0
@prisma/client : 4.16.0
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine b20ead4d3ab9e78ac112966e242ded703f4a052c (at node_modules/.pnpm/@prisma+engines@4.16.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli b20ead4d3ab9e78ac112966e242ded703f4a052c (at node_modules/.pnpm/@prisma+engines@4.16.0/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm : @prisma/prisma-fmt-wasm 4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c
Default Engines Hash : b20ead4d3ab9e78ac112966e242ded703f4a052c
Studio : 0.484.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (7 by maintainers)
Commits related to this issue
- fix(client): Default selection for composite lists Fix #19880 — committed to prisma/prisma by SevInf a year ago
- fix(client): Default selection for composite lists (#19887) * fix(client): Default selection for composite lists Fix #19880 * Add tests for optional composites — committed to prisma/prisma by SevInf a year ago
- fix(client): Default selection for composite lists (#19887) * fix(client): Default selection for composite lists Fix #19880 * Add tests for optional composites — committed to prisma/prisma by SevInf a year ago
- fix(client): Optional composites Fix #19880 — committed to prisma/prisma by SevInf a year ago
- fix(client): Optional composites (#19920) Fix #19880 — committed to prisma/prisma by SevInf a year ago
- fix(client): Optional composites (#19920) Fix #19880 — committed to prisma/prisma by SevInf a year ago
- fix(client): Default selection for composite lists (#19887) * fix(client): Default selection for composite lists Fix #19880 * Add tests for optional composites — committed to prisma/prisma by SevInf a year ago
- fix(client): Optional composites (#19920) Fix #19880 — committed to prisma/prisma by SevInf a year ago
Still having this issue with 4.16.1 Generated types have objects, scalars and composites on them breaking our codebase relying on them
I tried with the dev version that had the fix and types are still not being generated with the right payload
@prisma/client@4.16.1-dev.7
4.16.2-dev.1 seems to be working now, our schema is kind of beefy, 450 lines so I assume I’ts working
@SevInf I’m not getting anymore type errors using
4.16.2-dev.1on my repo.@pheuter thank you, I was able to reproduce the issue with your information. We are working on a fix at the moment. Fix will make it into patch release we are publishing soon.
My case is similar to @pheuter. I have an optional type on a model that is breaking.
@SevInf Looks like 4.16.1 was just a partial fix that only examined my one cherry picked example above. On 4.16.1, I continue to see similar errors involving
Payloadtypes containingobjectsandscalars.It’s somewhat worrying that a big, popular library like Prisma does not have an internal test suite with at least one schema.prisma file containing models, types, and fields that are commonly found in a MongoDB configuration. I don’t understand how you’re completely at the mercy of users reporting breaking bugs on released versions to only then uncover these issues…
Anyway, here is another example similar to above, this time the nested type is optional instead of an array:
Again, I will reiterate my concern from above that this is a very standard and basic use case that should have easily failed some tests on your side, and the fact that you solely went off my one example above that used a nested array and didn’t look at any other variations is not ideal.
thanks a lot, i’ll update our dev branch and see how it goes!
I’m seeing the same issues that’s causing hundreds of type errors in our codebase now. Here is one example:
schema.prisma:
Server ts function:
Generated .prisma/client/index.d.ts:
This new
EmergencyContactPayloadis causing issues since it contains fields likeobjectsandscalarsinstead of the type of the actualEmergencyContact./cc @SevInf
Looks like
4.16.2fixes the issue, thanks.4.16.2-dev.1 fixes my issue
latest version did not work for us too, some types are still causing errors. We will stick to 4.15.0 for now as I really dont want to manage versions on 3 servers 🫠
@dovidk could you share the reproduction? The code you are executing and the models it uses. The one @pheuter shared before is fixed in 4.16.1 and we have nothing else that would allow us to reproduce the issue.