Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No PrismaClientKnownRequestError if error in transaction #7399

Closed
Tracked by #7956
remioo opened this issue Jun 1, 2021 · 4 comments · Fixed by #8384
Closed
Tracked by #7956

No PrismaClientKnownRequestError if error in transaction #7399

remioo opened this issue Jun 1, 2021 · 4 comments · Fixed by #8384
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: error topic: transaction
Milestone

Comments

@remioo
Copy link

remioo commented Jun 1, 2021

Bug description

If you attempt to delete a row which does not exist in a transaction, you get a

Error: Error occurred during query execution:
InterpretationError("Error for binding \'0\'", Some(QueryGraphBuilderError(RecordNotFound("Record to delete does not exist."))))

If you attempt the same without transaction, you get a PrismaClientKnownRequestError with a code P2025, which is expected.

How to reproduce

With this code:

 try {
    const user = await dboClient.user.delete({where: {user_id: '9a535076-59f2-4145-9232-7302d82313d0'}});
    console.log(user);
  } catch (e) {
    console.log(e.toString() + '\n' + JSON.stringify(e));
  }

Output is the following. Error raised is a PrismaClientKnownRequestError

Error:
Invalid `prisma.user.delete()` invocation:
  An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
{"code":"P2025","clientVersion":"2.23.0","meta":{"cause":"Record to delete does not exist."}}

However, if you wrap this in a transaction,

  try {
    const [,user] = await dboClient.$transaction([
      dboClient.user.findUnique({where: {user_id: '9a535076-59f2-4145-9232-7302d82313d0'}}),
      dboClient.user.delete({where: {user_id: '9a535076-59f2-4145-9232-7302d82313d0'}})
    ]);
    console.log(user);
  } catch (e) {
    console.log(e.toString() + '\n' + JSON.stringify(e));
  }

Output is the following:

Error: Error occurred during query execution:
InterpretationError("Error for binding \'0\'", Some(QueryGraphBuilderError(RecordNotFound("Record to delete does not exist."))))
{"clientVersion":"2.23.0"}

Expected behavior

Even in the transaction, Error should be a PrismaClientKnownRequestError with a code P2025

Prisma information

Schema can be as simple as that

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.23.0
@prisma/client       : 2.23.0
Current platform     : windows
Query Engine         : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio               : 0.393.0

@remioo remioo added the kind/bug A reported bug. label Jun 1, 2021
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: error topic: transaction process/candidate labels Jun 1, 2021
@pantharshit00
Copy link
Contributor

I can reproduce this with 2.25.0-dev.30 , we need to check the error handling here.

@pantharshit00 pantharshit00 removed their assignment Jun 9, 2021
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 9, 2021
@remioo

This comment has been minimized.

@janpio

This comment has been minimized.

@remioo

This comment has been minimized.

@janpio janpio added the team/client Issue for team Client. label Jun 30, 2021
@millsp millsp linked a pull request Jul 31, 2021 that will close this issue
@millsp millsp added this to the 2.29.0 milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: error topic: transaction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants