|
Hello, I'm having trouble when upgrading the prisma version in my project. there are no schema errors and upgrading is smooth. But on some update queries where we had interactive transactions, it throws error: "All elements of the array need to be Prisma Client promises. Hint: Please make sure you are not awaiting the Prisma client calls you intended to pass in the $transaction function." I have following code inside the function: So I guess what I'm asking now, is since this way doesn't work anymore,how can I combine interactive transactions,with regular queries to execute both of them transactionally? Any help or insights are greatly appreciated, I've been stuck on this for quite some time now... Apologies if question is not formatted well or if my explanation is not well worded, it's my first time asking question on this platform Thank you |
Replies: 2 comments 4 replies
|
Hey @Tseredian 👋 The error is correct, you cannot nest a First of all, a In other words, because your queries are already being run in a transaction, you don't need to pass them to the let transactions = [];
transactions.push(
this.prismaService.$transaction(async (tx) => {
let update = await tx.table1.update({
where: {
id: id
},
data: {
//some data
}
})
if(some condition) {
await tx.table2.update();
}
}
)
//some other transactions are added
let results = [];
for (const tx of transactions) {
results.push(await tx);
}
return results; |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
Hey @Tseredian 👋 The error is correct, you cannot nest a
$transactionin a batch$transactionthis way. So if that worked, it was most likely a bug because this error message exists for a long time. That said, I am here to help you!First of all, a
PrismaPromiserepresents anything that will issue a query. So that is all the raw queries as well as all the model queries.PrismaPromisescan be chained on (ie. fluent API) on models, but most importantly they provide a way to inject them with a transaction context - be it in interactive transactions or in batch transactions.$transactiondoes not return aPrismaPromise, so you cannot nest them.In other words, because your queries are already…