New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concurrent relation upserts conflict #9751
Comments
Debug output
|
Related to #8612. Concurrency control in prisma is a lie. |
Since it's all in one block, you should be able to stick this in a transaction We do have a problem when you're unable to stick the code in a block and the block is concurrent, see #3242 . |
So, this must be a fundamental flaw with Prisma and how it works, because I get this error when I run this across multiple requests and the actual upsert is inside a transaction. And the idea that "Hey folks, this is expected behavior" is the response in #3242 is pretty ridiculous. This was also added as a milestone for 2.19 and seems to have been left behind? |
Can still reproduce this with 4.3.1. Logs: https://gist.github.com/pimeys/f3831809ac388a6c9b6ef8a720d8dce9 |
Prisma Upserts are very powerful and support very nested upserts. This can lead to a Unique constraint error being thrown. We have updated our docs with why this happens and what to do in that situation. |
Just wrap the [settings] = await prisma.$transaction([
prisma.settings.upsert({
where: { sub },
update: {},
create: { sub },
}),
]); |
I'm seeing this issue on transactions as well. My case scenario is different but not that much, I've got a collection with an unique constraint on a value, but that constraint needs to be case insensitive (this is mongodb btw). The result is duplicates everywhere because prisma doesn't guarantee that other transaction will start execution as my first arriving transaction has started execution, hence data corruption. I don't believe my case use is so uncommon, what's the recommended course of action to ensure that two commands get executed in an "atomic" way? |
Open a new issue or discussion please instead of commenting on a closed bug report. Thanks. |
For those who are reporting concurrency issues, it would help if you noted what isolation level you're running in. Obviously that has a big effect on concurrency in general, and that needs to be used when reproducing your problems. |
Bug description
Running multiple upserts concurrently and receiving the error:
How to reproduce
https://github.com/dariusj18/prisma_playground/tree/prisma_9751
Expected behavior
No errors, upserts happen as expected
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: