PrismaP
Prisma7mo ago
3 replies
Spencer S

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 }
});


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?
Was this page helpful?