ali
06/10/2021, 5:25 PM// WORKS - (rollback of write2 happens if write1 fails)
const write1 = prisma.user.create()
const write2 = prisma.post.create()
await prisma.$transaction([write1, write2])
// BROKEN? - (write2 is NOT rolled back if write1 fails)
const write1 = prisma.user.create()
const write2 = prisma.post.create()
write2.then(() => console.log('something happened'))
await prisma.$transaction([write1, write2])
Is this behavior expected?Daniel Norman
write2.then(() => console.log('something happened')) you are initiating the query and excluding it from the transaction you’re creating in the next line.James Fox
06/10/2021, 7:40 PM.then trigger a side effect of executing the transaction.
If that is indeed the expected behavior, could you point out the source code or docs about it?
I know that the return value of prisma executions is not a “normal” promise (looks to be PrismaPromise<A> = Promise<A> & {[prisma]: true}), but the semantics of .then are to invoke a callback once the task has been completed, not to trigger it to happen.James Fox
06/10/2021, 8:48 PMJames Fox
06/10/2021, 8:55 PM.promise which lets you tap into the execution without triggering it.Ryan
08/12/2021, 6:32 AM