Skip to content
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

Add a remark about upsert’s race conditions #3910

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ const user = await prisma.user.update({
#### Remarks

- To perform arithmetic operations on update (add, subtract, multiply, divide), use [atomic updates](#atomic-number-operations) to prevent race conditions.
- Prisma performs the upsert by first executing a `SELECT` query to check if the record exists, followed by an `INSERT` or `UPDATE` query depending on the result of the `SELECT` query. It [currently](https://github.com/prisma/prisma/issues/9972) does not use the `ON CONFLICT` or the `ON DUPLICATE KEY` clause, so [two simultaneous upserts with the same `UNIQUE` key can result in a “Unique constraint failed” error](https://github.com/prisma/prisma/issues/3242). It is your application’s responsibility to handle the [P2002](error-reference#p2002) error and retry the upsert.

#### Reference

Expand Down