Skip to content

No PrismaClientKnownRequestError if error in transaction #7399

Closed

Description

@remioo

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

Activity

  1. added
    kind/bug
    on Jun 1, 2021
  2. added
    bug/1-unconfirmed
    on Jun 1, 2021
  3. pantharshit00 commented on Jun 9, 2021

    @pantharshit00
    Contributor

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

  4. removed their assignment
    on Jun 9, 2021
  5. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Jun 9, 2021
  6. remioo commented on Jun 18, 2021

    @remioo
    Author
  7. janpio commented on Jun 18, 2021

    @janpio
  8. remioo commented on Jun 21, 2021

    @remioo
    Author
  9. linked a pull request that will close this issuefeat(client): interactive transactions #8384on Jul 31, 2021
  10. added this to the 2.29.0 milestone on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtopic: errortopic: transaction

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions