$transaction doesn't rollback in case any transaction fails
See original GitHub issueBug description
I am trying to use Prisma transactions as specified here. My transaction is not rolling back in case of an error.
Example
const txn1 = this.prisma.table1.create({
data: {
name: `Test 1`
},
});
const txn2 = this.prisma.table1.create({
data: {
name: undefined //`Test 2`,
},
});
const transactionResults = await this.prisma.$transaction([txn1, txn2]);
name is a mandatory column so when I send undefined, txn2 fails but txn1 still creates a record in the table even though it should rollback as txn2 failed.
How to reproduce
Sample code shared above. Try to execute it with a test table.
Expected behavior
Transaction 1 insert should rollback as transaction 2 failed.
Prisma information
Environment & setup
- OS: MacOS Catalina 10.15.1, Running inside docker
node:14.15.4-alpine - Database: PostgreSQL
- Node.js version: v14.15.4
- Prisma version:
prisma : 2.16.0
@prisma/client : 2.16.0
Current platform : linux-musl
Query Engine : query-engine 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules/prisma/node_modules/@prisma/engines/query-engine-linux-musl)
Migration Engine : migration-engine-cli 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules/prisma/node_modules/@prisma/engines/migration-engine-linux-musl)
Introspection Engine : introspection-core 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules/prisma/node_modules/@prisma/engines/introspection-engine-linux-musl)
Format Binary : prisma-fmt 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-linux-musl)
Studio : 0.346.0
Preview Features : nativeTypes, createMany
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Spring Transaction - Do not rollback for error under specific ...
I do not want any rollback, especially since the NotificationService does not modify the database. How can I tell Spring that any exception ......
Read more >Spring @Transactional Rollback Handling | Geek Culture
The above example proves that the @Transactional annotation can roll back the transaction if the exception occurs. Take note, Spring only rolled back...
Read more >Transactions - Snowflake Documentation
When a DML statement or CALL statement in a transaction fails, the changes made by that failed statement are rolled back. However, the...
Read more >ROLLBACK TRANSACTION (Transact-SQL) - SQL Server
A transaction cannot be rolled back after a COMMIT TRANSACTION statement is executed, except when the COMMIT TRANSACTION is associated with a ...
Read more >Rollback Exception Strategy | MuleSoft Documentation
Usually, you use a rollback exception strategy to handle errors that occur in a flow that involve a transaction. If the transaction fails,...
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 Free
Top 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

Thanks for the quick fix @timsuchanek. Tested it on 2.17 and its working as expected.
To repeat what @pantharshit00 wrote: Please open a new issue @sreuter - I absolutely agree with your stance here and we should definitely improve this. Super important actually.