Bug description
PrismaClientKnownRequestError:
Invalid `prisma.document.upsert()` invocation:
Unique constraint failed on the fields: (`url`)
How to reproduce
return this.prisma.document.upsert({
where: { url },
create: {
url,
status: ProcessingStatus.PENDING,
},
update: {}, // Do nothing if document already exists
});
Sometimes this will throw the following:
PrismaClientKnownRequestError:
Invalid `prisma.document.upsert()` invocation:
Unique constraint failed on the fields: (`url`)
Expected behavior
Per the documentation, this usage of upsert should be eligible for the db version that should not have this error.
Prisma information
prisma@5.22.0
enum ProcessingStatus {
PENDING
UPLOADING
PROCESSING
COMPLETED
FAILED
}
model Document {
id String @id @default(cuid())
status ProcessingStatus
url String? @unique
@@index([status])
@@index([url])
}
// Add your code using Prisma Client
Environment & setup
- OS:
- Database: PostgreSQL
- Node.js version: 20
Prisma Version
prisma : 5.22.0
@prisma/client : 5.22.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v20.15.0
Query Engine (Node-API) : libquery-engine 605197351a3c8bdd595af2d2a9bc3025bca48ea2 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli 605197351a3c8bdd595af2d2a9bc3025bca48ea2 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2
Default Engines Hash : 605197351a3c8bdd595af2d2a9bc3025bca48ea2
Studio : 0.503.0
Preview Features : metrics, relationJoins
Bug description
How to reproduce
Sometimes this will throw the following:
Expected behavior
Per the documentation, this usage of
upsertshould be eligible for the db version that should not have this error.Prisma information
prisma@5.22.0
// Add your code using Prisma ClientEnvironment & setup
Prisma Version