Prisma transaction cannot read its own writes when mixing standard and raw queries.

Hello! I am using Prisma 5.21.0 with Postgres 15.5. I've noticed that when I create a transaction, writes performed with $executeRaw are not seen by queries made using the standard ORM interface and vice-versa. Looking at the logs for my postgres service shows that these queries have a different postgres Process ID, whereas all standard ORM calls within a transaction have the same Process ID. For example:
prisma.$transaction(async (txn) => {
await txn.$executeRaw(Prisma.sql`
update user
set name=${newUsername}
WHERE id=${userId}::uuid;`);
const retUser = await txn.user.findUniqueOrThrow({
select: { name: true },
where: { id: userId }
});
prisma.$transaction(async (txn) => {
await txn.$executeRaw(Prisma.sql`
update user
set name=${newUsername}
WHERE id=${userId}::uuid;`);
const retUser = await txn.user.findUniqueOrThrow({
select: { name: true },
where: { id: userId }
});
In the above code block, retUser will have its old name. queryRaw has the same behavior, with and without Prisma.sql templating. Is this expected?
3 Replies
Prisma AI Help
Prisma AI Help6mo ago
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Spencer S
Spencer SOP5mo ago
Anyone see this before?
Nurul
Nurul5mo ago
Hey! Can you let me know if this occurs in latest prisma version 6.12 as well?

Did you find this page helpful?