question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma transaction does not work in case of error from prisma

See original GitHub issue

Bug description

I am using postgres database. When using the batch transaction API prisma.$transaction, when there are multiple queries to be run, and if there is a delete query for the same id present 2 times, then either the transaction does not get rolled back or the queries as part of triggers alone are not rolled back, leading to inconsistent data.

I have triggers created on the table to do certain other changes when INSERT or UPDATE queries are run.

How to reproduce

  1. Create a prisma transaction with an array of queries
  2. Have an update query first, then a delete query, then another update query and then the same delete query as previous
  3. Try to await on the prisma.$transaction so that the queries are executed
  4. Prisma throws an error because the 2nd delete query fails
  5. The transaction is either not rolled back or trigger queries alone are not rolled back, leading to inconsistent data

Expected behavior

No response

Prisma information

Due to sensitive nature of my queries, I cannot share them.

Environment & setup

  • OS: centos 8
  • Database: PostgreSQL 13
  • Node.js version: v14.20.0

Prisma Version

@prisma/client       : 2.19.0
Current platform     : rhel-openssl-1.0.x
Query Engine         : query-engine c1455d0b443d66b0d9db9bcb1bb9ee0d5bbc511d (at node_modules/@prisma/engines/query-engine-rhel-openssl-1.0.x)
Migration Engine     : migration-engine-cli c1455d0b443d66b0d9db9bcb1bb9ee0d5bbc511d (at node_modules/@prisma/engines/migration-engine-rhel-openssl-1.0.x)
Introspection Engine : introspection-core c1455d0b443d66b0d9db9bcb1bb9ee0d5bbc511d (at node_modules/@prisma/engines/introspection-engine-rhel-openssl-1.0.x)
Format Binary        : prisma-fmt c1455d0b443d66b0d9db9bcb1bb9ee0d5bbc511d (at node_modules/@prisma/engines/prisma-fmt-rhel-openssl-1.0.x)
Studio               : 0.358.0
Preview Features     : createMany

The same issue happens on the latest prisma version 4.1.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rajesh1158commented, Aug 4, 2022

I get the below error:

An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
0reactions
janpiocommented, Nov 25, 2022

Closing then until someone provides more information. Please comment or open a new issue. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma.$transaction: Benchmark produces unexpected results
My project uses prisma's transactions and under high load, prisma throws an unmeaningful error Error at Object.transaction (/.
Read more >
Handling exceptions and errors (Reference) - Prisma
This page covers how to handle exceptions and errors. ... Error handling for the MongoDB connector is incomplete. ... const client = new...
Read more >
Transactions and batch queries (Reference) - Prisma
Interactive transactions: pass a function that can contain user code including Prisma Client queries, non-Prisma code and other control flow to be executed ......
Read more >
Error message reference - Prisma
Prisma Client throws a PrismaClientUnknownRequestError exception if the query engine returns an error related to a request that does not have an error...
Read more >
Transactions - Prisma
Prisma Client solves the problem with nested writes. The following query creates a team, creates a user, and connects the records in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found