Repository navigation
Open
prisma/prisma-engines
#3418Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/enginesIssue for tech Engines.topic: composite ids
Milestone
Description
Bug description
I'm having a model that references itself with a composite key including a clientId. One field of the reference is optional, the other is not (cf. #6042).
When updating the reference, it seems, prisma is trying to set both fields to null, which violates the constraint:
PrismaClientKnownRequestError3 [PrismaClientKnownRequestError]:
Invalid `prisma.object.update()` invocation:
Null constraint violation on the fields: (`clientId`)
How to reproduce
- Use prisma.schema below
- Create first object:
o1 = await prisma.object.create({ data: {clientId: 1}}) - Create second object referencing the first one:
o2 = await prisma.object.create({ data: { clientId: 1, otherUuid: o1.uuid } }) - Add reference to first object as well:
prisma.object.update({ data: { otherUuid: o2.uuid }, where: { clientId_uuid: { clientId: 1, uuid: o1.uuid } }, }) - Try to update the first object:
prisma.object.update({
data: {
otherObject: {
connect: { clientId_uuid: { clientId: 1, uuid: o2.uuid } },
},
},
where: { clientId_uuid: { clientId: 1, uuid: o1.uuid } },
})
Expected behavior
The update should update the field otherUuid (in this case unchanged), bot not try to set clientId to null.
Prisma information
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model object {
clientId Int @db.Integer
uuid String @default(uuid()) @db.Uuid
otherUuid String? @db.Uuid
otherObject object? @relation(fields: [clientId, otherUuid], references: [clientId, uuid])
otherObjectReverse object? @relation("objectToobject")
@@id([clientId, uuid])
}
Environment & setup
- OS: Windows
- Database: PostgreSQL
- Node.js version: 16.6.2
Prisma Version
Environment variables loaded from .env
prisma : 2.29.1
@prisma/client : 2.29.1
Current platform : windows
Query Engine : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio : 0.419.0
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/enginesIssue for tech Engines.topic: composite ids
Activity
some-user123 commentedon Sep 8, 2021
Can be reproduced with 3.0.1 as well.
pantharshit00 commentedon Sep 9, 2021
Thanks for the details, I can reproduce this issue.
Posted a minimal reproduce here for the team which they can run easily: https://github.com/harshit-test-org/prisma-issue-8858
some-user123 commentedon Nov 2, 2021
Is there an ETA for a fix? Is there anything I could do to support analysis/debugging?
pimeys commentedon Sep 5, 2022
This is still happening with 4.3.2. Needed to do some modification so it works with the latest version.
schema.prisma:
script.ts:
The debug log:
fix: nested connect should disconnect only optional fields (#3418)
janpio commentedon Dec 1, 2022
(PR that closed this was reverted)
mcbethio commentedon Feb 4, 2023
@Weakky is the milestone correct for this issue? I think it should be 4.10.0 right?