Repository navigation
Closed
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: $transactionRelated to .$transaction(...) Client APItopic: errortopic: transaction
Milestone
Description
Bug description
While trying to auto-generate slugs for user-made pages at Copyfolio, we noticed that unique constraint violation errors aren’t caught properly inside a prisma.$transaction.
How to reproduce
-
Have a model with a unique constraint, e.g. a
Sitewith a globally unique URLslug. -
Run some code which is meant to detect unique
slugconstraint violation errors – and then auto-generate a new slug to try with, but that isn’t part of the code below:
/* Fill our database with some initial data */
await prisma.site.create({ id: "1", slug: "taken-by-1" });
await prisma.site.create({ id: "2", slug: "another" });
try {
await prisma.$transaction([
prisma.site.updateMany({
where: { id: "2" },
data: { slug: "taken-by-1" },
}),
/* Any other site update is required for the test to fail */
prisma.site.update({
where: { id: "2" },
data: { id: "2" },
}),
]);
} catch (error) {
if (
error instanceof PrismaClientKnownRequestError &&
error.code === "P2002"
) {
console.debug("Unique constraint violation detection works");
} else {
console.error("Unknown error, as violation detection fails");
throw error;
}
}It should throw an unknown error, which isn’t the expected behavior. However, then using previewFeatures = ["nApi"], the code above works as expected.
Expected behavior
No response
Prisma information
model Site {
id String @id @default(cuid())
slug String @unique
}Environment & setup
- OS: mac OS v11.4
- Database: PostgreSQL 12/13
- Node.js version: v14.16.1
Prisma Version
prisma : 2.23.0
@prisma/client : 2.23.0
Current platform : darwin
Query Engine : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio : 0.393.0
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: $transactionRelated to .$transaction(...) Client APItopic: errortopic: transaction
Activity
pantharshit00 commentedon May 28, 2021
I can reproduce this. Looks like we aren't serializing the error properly for child process + http version and it is properly serialized in the NAPI implementation.
We should fix this as NAPI is not stable yet.
pantharshit00 commentedon May 28, 2021
For internal reference:
Error thrown with child process + http bridge implementation:
Error thrown with the NAPI implementation:
Notice the proper stack trace rather than the engine panic dump.
matthewmueller commentedon Jun 2, 2021
Just to clarify because it took me a couple reads.
[-]Unique constraint error inside a transaction throws unparsed error – but works fine when using N-API[/-][+]Unique constraint error inside a transaction throws unparsed error (but works fine when using Node API)[/+]matthewmueller commentedon Jun 28, 2021
Could this be related to: #6705?
Sytten commentedon Jun 28, 2021
I would favour a breaking change in the http protocol vs a keeping a broken implementation around.
millsp commentedon Jul 31, 2021
Hey @kripod, I'm so happy to see you here! This is fixed in the upcoming #8384