You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The preview for interactive transactions (iTX) doesn't allow for setting the isolation level when starting the transaction. However, there are plenty of scenarios where setting the isolation level is required to make use of iTX.
Reacted by Daniel Norman, Tim Reynolds, GaetanD, Mateusz Nowak, zach, Toni Villena, Tasin Ishmam, Carolin Maisenbacher, Eyþór Magnússon, Tine Jozelj and 34 more
Reacted by Ahmet Kuris, ravshansbox, Momen, herenickname, Max Heinritz and Richard J
Reacted by Ahmet Kuris, ravshansbox, Momen, herenickname and Max Heinritz
Reacted by Ahmet Kuris, ravshansbox, Momen, herenickname and Max Heinritz
I just wanted to say that this is an important feature.
I'm using optimistic concurrency control in conjunction with $transaction calls (both array and functional types). Because MySQL/MariaDB default to the REPEATABLE READ transaction isolation level, there are times where OCC won't work correctly.
If two requests enter the transaction around the same time, they will both see the old entity version and succeed with the updateMany. We need to use a transaction level like READ COMMITTED so that both requests see the latest version of the table, rather than a consistent snapshot created at the start of the transaction.
Right now I'm doing this with await this.prisma.$executeRaw`SET TRANSACTION ISOLATION LEVEL READ COMMITTED`; just before I start the call to prisma.$transaction.
SET TRANSACTION ISOLATION LEVEL READ COMMITTED sets the transaction isolation level for the next transaction within the current database session, and I'm not convinced that the "next transaction" is necessarily going to be the one I intend to start on the next line. Some other request could potentially start a transaction first. Since I'm using a single prisma object for the entire app (as per the docs), couldn't this other transaction be within the same database session and "steal" my isolation level?
I'm hoping that something like the feature being proposed could ensure that the isolation level is used only for the intended transaction.
Reacted by Guillaume Simard, Jan Pöschko, Cristiano, Salem Korayem, Alessio Di Crescenzo and herenickname
Reacted by zach, elderapo and Cristiano
Reacted by Toni Villena, elderapo and herenickname
This functionality is now available in the latest version of Prisma.
Reacted by Patrik Valkovic, Michał Lytek, ravshansbox, Salem Korayem, Dave Welsh, Tine Jozelj, Tim Lawson, jeremyisatrecharm, Takafumi Hirata, Ezra Khairan Permana and 2 more
Activity
move-zig commentedon Mar 20, 2022
I just wanted to say that this is an important feature.
I'm using optimistic concurrency control in conjunction with $transaction calls (both array and functional types). Because MySQL/MariaDB default to the
REPEATABLE READtransaction isolation level, there are times where OCC won't work correctly.If two requests enter the transaction around the same time, they will both see the old entity version and succeed with the
updateMany. We need to use a transaction level likeREAD COMMITTEDso that both requests see the latest version of the table, rather than a consistent snapshot created at the start of the transaction.Right now I'm doing this with
await this.prisma.$executeRaw`SET TRANSACTION ISOLATION LEVEL READ COMMITTED`;just before I start the call toprisma.$transaction.SET TRANSACTION ISOLATION LEVEL READ COMMITTEDsets the transaction isolation level for the next transaction within the current database session, and I'm not convinced that the "next transaction" is necessarily going to be the one I intend to start on the next line. Some other request could potentially start a transaction first. Since I'm using a singleprismaobject for the entire app (as per the docs), couldn't this other transaction be within the same database session and "steal" my isolation level?I'm hoping that something like the feature being proposed could ensure that the isolation level is used only for the intended transaction.
garrensmith commentedon Aug 12, 2022
This functionality is now available in the latest version of Prisma.