Middleware has different behavior for transactions in array vs. interactive transactions. #19145
Labels
bug/2-confirmed
Bug has been reproduced and confirmed.
kind/bug
A reported bug.
team/client
Issue for team Client.
topic: cockroachdb
topic: interactiveTransactions
topic: middleware
topic: prisma-client
topic: $transaction
Related to .$transaction(...) Client API
topic: transaction
topic: $transaction([...])
Sequential Prisma Client operations
Bug description
We have implemented retry middleware to handle various retryable errors or transactions that come back from CockroachDB (retryable transactions, connection draining, etc.). A very simplified, not-actually-used-in-prod-because-it-would-be-a-bad-idea version is here:
I've discovered that this middleware will have different outcomes for using
$transaction
, depending on whether I use the array form or interactive transaction:If in array form, after running you will still have a record created from
createARecord
(unexpected). If in itx form, there will be no record afterward (expected).It seems related to #7584, but that issue was about blocking query execution, my concern is about what appears to be not honoring transaction guarantees.
How to reproduce
Prisma model:
App code (roughly, omitting some boilerplate):
And finally two tests. The first one fails, the second one does not.
Expected behavior
The same outcome happens for both forms of
$transaction
, where no records are created after running the transaction with the middleware.Discussion
If I
console.log
the params before callingawait next(params)
, we get this output for the array output case:And this for the itx case, notice it doesn't ever call with the good data payload again:
Here are some other issues that have been filed, which all seem related but don't exactly articulate the issue I'm raising, so I figured I'd keep it separate for now:
Prisma information
shown above
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: