#26804: update_or_create() updates all columns, which could cause a race
condition
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: jensen-
| cochran
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: update_or_create | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jensen-cochran):
The race condition in get_or_create would be: get_or_create does not find
a matching row, then another process inserts a row that get_or_create
would have matched, then get_or_create inserts it's row. Now, two rows in
the table exist with duplicate values (for the columns that were being
searched against).
If you have a unique index in your database for the columns you passed to
get_or_create and this race condition occurred, you would not have
duplicate values inserted. Instead, you would get a db exception. So it is
possible to avoid the overhead of the transaction in some cases, but only
if we know that the columns are unique/unique_together.
--
Ticket URL: <https://code.djangoproject.com/ticket/26804#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.162440e9eac519adad64dddc3e8459b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.