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

callback-free-itx: Fixed $rollback and added $transaction #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vaharoni
Copy link

This PR contains the following improvements:

  1. Fixes the $rollback behavior
    Currently, the promise being rejected when calling $rollback is caught and ignored. This means the original target txClient is unaware that an exception was raised during the execution of its $transaction, and therefore performs a commit rather than a rollback.

  2. Adds a $transaction method
    One of the goals of this extension is to allow integration tests per issue 12458. The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a global beforeEach block, and rolling back that transaction in afterEach. This allows full test independence, as rolling back the transaction means the database remains unchanged between tests. The code being tested should be unaware the prisma client is being mocked. It should be able to invoke prisma.$transaction if it needs to. However, in the current extension implementation this does not work. This PR enables this behavior by proxying the $transaction method, sending txClient to the callback.

@janpio janpio changed the title Fixed $rollback and added $transaction callback-free-itx: Fixed $rollback and added $transaction May 23, 2024
@acron0
Copy link

acron0 commented Jun 5, 2024

Would be nice to see this

@gyunseo
Copy link

gyunseo commented Jul 11, 2024

@vaharoni

The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a global beforeEach block, and rolling back that transaction in afterEach

How can I specifically achieve the above content with code?

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

Successfully merging this pull request may close these issues.

3 participants