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.

$transaction doesn't rollback in case any transaction fails

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
codeslayer1commented, Feb 16, 2021

Thanks for the quick fix @timsuchanek. Tested it on 2.17 and its working as expected.

0reactions
janpiocommented, May 18, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

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