#20429: Add QuerySet.update_or_create method
-------------------------------------+-------------------------------------
     Reporter:  tunixman             |                    Owner:
         Type:  New feature          |  elektrrrus
    Component:  Database layer       |                   Status:  assigned
  (models, ORM)                      |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by loic84):

 As mentioned on IRC, I believe this method suffers from a race-condition
 (especially if used in a view) which should be documented.

 {{{
 Warning:

 This method is prone to race-condition and can result in multiple rows
 being
 inserted simultaneously if uniqueness is not enforced at the database
 level
 (see either ``unique`` or ``unique_together``).

 During a race where uniqueness is inforced, all simultaneous calls to
 ``create_or_update`` but one will raise an ``IntegrityError``.

 Without uniqueness inforcement, any ``create_or_update`` call with the
 same set
 of parameters that happens after a race will raise
 ``MultipleObjectsReturned``.

 }}}

 Like `get_or_create`, it might be good to recommend it as a convenience
 for scripts rather than something to use in a view.

 Refs #12579

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20429#comment:22>
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/066.8d260bf723cf113d6bc53532441fb874%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to