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

fix: rollback called explicitly working. #47

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

Conversation

jspears
Copy link

@jspears jspears commented Jan 20, 2024

Rollback was not working when explicitly called.

This PR changes the script to test that and actually call rollback. This code should be much more rigorously tested than this, but alas I do not have time.

@@ -33,12 +34,13 @@ const prisma = new PrismaClient({ log: ["query"] }).$extends({
) {
const tx = prisma.$transaction((txClient) => {
setTxClient(txClient as unknown as Prisma.TransactionClient);

return txPromise.catch((e) => {
if (e === ROLLBACK) return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this swallows the exception that actually triggers the rollback.

@@ -17,7 +18,7 @@ const prisma = new PrismaClient({ log: ["query"] }).$extends({

// a promise for getting the tx inner client
const txClient = new Promise<Prisma.TransactionClient>((res) => {
setTxClient = (txClient) => res(txClient);
setTxClient = res;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary function.

const tx2 = await prisma.$begin();
await tx2.user.findMany();
// const tx2 = await prisma.$begin();
// await tx2.user.findMany();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me the important part to show in transactions is rollback, maybe we should show both.

gyunseo added a commit to skkuding/codedang that referenced this pull request Mar 16, 2024
@gyunseo
Copy link

gyunseo commented Mar 16, 2024

@jspears Thanks!! Your PR helped me a lot.

gyunseo added a commit to skkuding/codedang that referenced this pull request Mar 18, 2024
* feat(be): implement transaction extension for prisma client
prisma/prisma-client-extensions#47 참고하여 작성했습니다

* feat(be): add transaction extension on index ts file

* feat(be): implement transaction rollback for group service unit test

* test(be): add comments and type

* test(be): add await keyword

* test(be): add chai exclude

* test(be): delete override prisma service func

* test(be): increase timeout for before each hook

* test(be): disable timeout for before each hook

* test(be): add comment

* test(be): fix comment
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.

2 participants