Transactions don't seem to respect parallel requests #508
Replies: 1 comment 1 reply
-
Hello @EvHaus, Overall, I would say that something like the approach you shared should probably work just fine, although we do tend to have users run into difficulties with Prisma transactions if they are accidentally kept open for an extended period of time, which can result in users encountering our 20 second transaction timeout limit, but that's different than the error you shared. I don't know if it's a typo or something else, but out of hte information you provide the unique index seemed to stand out as potentially having a mistake or referencing a field that doesn't exist in the table definition you provided:
I would be curious if each instance of Based on a quick read through of the Prisma docs here: It feels like using This one feels like it'll require a bit more experimentation on the Prisma side to achieve the expected behavior, but unless you are also testing against a vanilla MySQL 8 instance and observing behavior that's different from the PlanetScale database, I would expect them to mostly be behaving the same in this situation. |
Beta Was this translation helpful? Give feedback.
-
I'm using PlanetScale with Prisma. I have a model like this:
The
thingId
value is a string that looks like this:RP-1
orXX-999
, etc... It's a value that must be unique within anorganizationId
scope and should be incremented by 1 for each new insert. Since it's a string field, I cannot useautoincrement()
on it. I was hoping to use transactions for this but it's not working for me. My transaction looks like this:This works just fine if I call
createThing()
one at a time, but if I try to simulate many different things being created concurrently via:I start to get these errors:
To me this seems like a limitation/bug in PlanetScale in that it doesn't lock the table during ongoing transactions. I couldn't find anything in the PlanetScale docs around this so I'm wondering if perhaps this is an undocumented limitation or maybe I'm doing something stupid.
Beta Was this translation helpful? Give feedback.
All reactions