Closed hokaccha closed 7 months ago
@hokaccha Thanks for your reporting.
I reproduced this message.
And I can suppress the 25P02
error using nested transaction like this:
/* user.test.ts */
test("ensureUser", async () => {
const data = { id: 1, name: "foo" };
// succeed
expect(await ensureUser(jestPrisma.client, data)).toBe(true);
try {
await jestPrisma.client.$transaction(async () => {
// succeed
expect(await ensureUser(jestPrisma.client, data)).toBe(true);
throw new Error();
});
} catch {}
expect(await jestPrisma.client.user.count()).toBe(1);
});
/* jest.config.mjs */
export default {
testEnvironment: "@quramy/jest-prisma-node/environment",
testEnvironmentOptions: {
enableExperimentalRollbackInTransaction: true, // Enable nested $transaction in test code
},
};
Here is full example: https://github.com/Quramy/jest-prisma-repro-141/pull/1/files .
And I can suppress the 25P02 error using nested transaction.
I see, it seems like this problem can be solved this way. Thank you.
As far as I'm concerned, it's okay to close this issue, but I'll leave the decision up to you 🙏
it's okay to close this issue, but I'll leave the decision up to you
Thanks. I'll write about this problem and the workaround to README's tips section.
When handling a unique constraint error, such as the following, executing a query after a unique constraint error occurs will result in an error.
I suspect this is due to PostgresSQL's limitation that if an error occurs during a transaction, subsequent queries cannot be issued.