-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Bug description
When attempting to update a model with an @autoincrement field while also updating relations in the same operation, Prisma throws an error. This prevents updating both scalar fields and relations in a single atomic operation.
Severity
🚨 Critical: Data loss, app crash, security issue
Reproduction
https://codesandbox.io/p/sandbox/vibrant-roman-tj9kd3?file=%2Fsrc%2Findex.ts
- Create a model with an @autoincrement field (in our case, userNumber)
- Try to update this field alone - this works correctly
- Try to update this field while also updating a relation (e.g., using upsert on a relation) - Prisma throws an error
Expected vs. Actual Behavior
Expected Behavior
All fields specified in the update operation, including @autoincrement fields, should be updated correctly alongside relation fields in the same operation.
Actual Behavior
An error is thrown when attempting to update an @autoincrement field in the same operation as a relation update.
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Currently on [email protected].
Workaround
No
Prisma Schema & Queries
// This works: updating only the userNumber
const updatedUser1 = await prisma.userWithAutoincrement.update({
where: { id: user.id },
data: { userNumber: 10 }
});
// userNumber is correctly updated to 10
// This fails with an error: cannot update userNumber when updating a relation
const updatedUser2 = await prisma.userWithAutoincrement.update({
where: { id: user.id },
data: {
userNumber: 20,
contactInformation: {
upsert: {
create: { email: "[email protected]" },
update: { email: "[email protected]" }
}
}
}
});
Typescript Error
Type '{ name: string; userNumber: number; contactInformation: { upsert: { create: { email: string; phone: string; }; update: { email: string; phone: string; }; }; }; }' is not assignable to type '(Without<UserWithAutoincrementUpdateInput, UserWithAutoincrementUncheckedUpdateInput> & UserWithAutoincrementUncheckedUpdateInput) | (Without<...> & UserWithAutoincrementUpdateInput)'.
Types of property 'contactInformation' are incompatible.
Type '{ upsert: { create: { email: string; phone: string; }; update: { email: string; phone: string; }; }; }' is not assignable to type 'undefined'.ts(2322)
And this works again, when leaving the userNumber
update
const updatedUser3 = await prisma.userWithAutoincrement.update({
where: { id: user.id },
data: {
contactInformation: {
upsert: {
create: { email: "[email protected]" },
update: { email: "[email protected]" }
}
}
}
});
Prisma Config
No response
Logs & Debug Info
// Debug logs here
Environment & Setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: 22
Prisma Version
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
prisma : 6.12.0
@prisma/client : 6.9.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v22.9.0
TypeScript : 5.8.2
Query Engine (Node-API) : libquery-engine 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
PSL : @prisma/prisma-schema-wasm 6.12.0-15.8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Schema Engine : schema-engine-cli 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash : 8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Studio : 0.511.0