Prisma transaction does not work in case of error from prisma
See original GitHub issueBug 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
- Create a prisma transaction with an array of queries
- Have an update query first, then a delete query, then another update query and then the same delete query as previous
- Try to await on the
prisma.$transaction
so that the queries are executed - Prisma throws an error because the 2nd delete query fails
- 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:
- Created a year ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I get the below error:
Closing then until someone provides more information. Please comment or open a new issue. Thanks!