Repository navigation
Closed
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: errortopic: transaction
Milestone
Description
Bug description
If you attempt to insert a row while in a transaction and a unique constraint fails, the error sent is:
ConnectorError(ConnectorError { user_facing_error: Some(KnownError { message: "Unique constraint failed on the fields: (`user_id`)", meta: Object({"target": Array([String("user_id")])}), error_code: "P2002" }), kind: UniqueConstrai
ntViolation { constraint: Fields(["user_id"]) } })
If not in a transaction, error is a PrismaClientKnownRequestError with code P2002
How to reproduce
Without transaction
try {
const user = await dboClient.user.create({data: {account_id: '1fe4ed1d-afe7-482c-be6b-430179776c4a', user_id: '9a535076-59f2-4145-9232-7302d82313d0'}});
console.log(user);
} catch (e) {
console.log(e.toString() + '\n' + JSON.stringify(e));
}Error:
Invalid `prisma.user.create()` invocation:
Unique constraint failed on the fields: (`user_id`)
{"code":"P2002","clientVersion":"2.23.0","meta":{"target":["user_id"]}}
With transaction
try {
const [,user] = await dboClient.$transaction([
dboClient.user.findUnique({where: {user_id: '9a535076-59f2-4145-9232-7302d82313d0'}}),
dboClient.user.create({data: {account_id: '1fe4ed1d-afe7-482c-be6b-430179776c4a', user_id: '9a535076-59f2-4145-9232-7302d82313d0'}})
]);
console.log(user);
} catch (e) {
console.log(e.toString() + '\n' + JSON.stringify(e));
}Error:
Error: Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: Some(KnownError { message: "Unique constraint failed on the fields: (`user_id`)", meta: Object({"target": Array([String("user_id")])}), error_code: "P2002" }), kind: UniqueConstrai
ntViolation { constraint: Fields(["user_id"]) } })
Expected behavior
Even in the transaction, Error should be a PrismaClientKnownRequestError with a code P2002
Prisma information
model User {
user_id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
}
Environment & setup
- OS: Windows
- Database: PostgreSQL
- Node.js version: v14.16.0
Prisma Version
prisma : 2.25.0
@prisma/client : Not found
Current platform : windows
Query Engine : query-engine c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt c838e79f39885bc8e1611849b1eb28b5bb5bc922 (at node_modules\prisma\node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : c838e79f39885bc8e1611849b1eb28b5bb5bc922
Studio : 0.402.0
Reacted by Jan Piotrowski and remolueoend
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: errortopic: transaction
Activity
pantharshit00 commentedon Jul 29, 2021
I can reproduce with
2.29.0-dev.5