Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Rollback Fails When Using withPgAdapter #6

Open
furkan-asani opened this issue Feb 6, 2025 · 0 comments
Open

Prisma Rollback Fails When Using withPgAdapter #6

furkan-asani opened this issue Feb 6, 2025 · 0 comments

Comments

@furkan-asani
Copy link

Hello Bemi-Team,

Summary

When wrapping the Prisma client with withPgAdapter, the rollback mechanism for interactive transactions fails. Specifically, if an error is thrown within a transaction, the changes are not reverted as expected.

Environment

• Prisma Client Version: 5.22.*
• withPgAdapter Version: 0.8.* (also reproduced with 0.7.*)
• PostgreSQL

Steps to Reproduce

  1. Setup:
    • Initialize a project using Prisma Client version 5.22..
    • Wrap your Prisma client instance with withPgAdapter (using version 0.8.
    or 0.7.*).

Example:

import { PrismaClient } from '@prisma/client';
import { withPgAdapter } from 'your-adapter-package';

const prisma = withPgAdapter(new PrismaClient());
  1. Create a Transaction:
    • Start an interactive transaction using prisma.$transaction() and perform one or more database operations.
  2. Trigger Rollback:
    • Within the transaction block, deliberately throw an error to trigger a rollback.

Example:

await prisma.$transaction(async (prismaTx) => {
  await prismaTx.user.create({ data: { name: 'Test' } });
  // Simulate an error to force rollback
  throw new Error('Intentional failure to trigger rollback');
});
  1. Observation:
    • Instead of rolling back the transaction, the changes made prior to the error persist (or the rollback mechanism is bypassed).

Expected Behavior

When an error is thrown within an interactive transaction, the entire transaction should be rolled back, ensuring that no partial changes remain in the database.

Observed Behavior

With the Prisma client wrapped using withPgAdapter, the rollback does not occur. This means that even after an error is thrown, the operations executed before the error are not reverted.

Additional Context

• This issue consistently appears with the mentioned versions of Prisma Client and the adapter.
• The problem seems specific to scenarios where the Prisma client is wrapped with withPgAdapter.
• Any insights into how the adapter might interfere with the transaction rollback process would be appreciated.

Request

Please advise if further details, such as a minimal reproduction repository or additional logs, would help diagnose the issue. Thank you for your time and efforts in looking into this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant