#36489: OneToOneField + concurrent get_or_create results in wrong object in 
field
cache
-------------------------------------+-------------------------------------
     Reporter:  Brian Atkinson       |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * cc: Simon Charette, Mariusz Felisiak (added)
 * component:  Uncategorized => Database layer (models, ORM)
 * stage:  Unreviewed => Accepted
 * type:  Uncategorized => Bug

Comment:

 Thank you Brian Atkinson for taking the time to create this ticket. I have
 reviewed the test case that you provided, which is quite helpful to
 understand your report.

 I was able to reproduce the issue as described. When a concurrent
 `get_or_create()` call results in an `IntegrityError`, the model instance
 created for the first attempt is incorrectly cached on the reverse side of
 the one-to-one relation. This leads to inconsistent behavior, such as
 accessing `parent.child` and getting an unsaved `Child` instance with
 `pk=None`.

 A few notes: I believe the issue is somewhere between the related
 descriptors and how the reverse 1-1 is set but I haven't been able to
 exactly pin point the precise place that needs fixing. Also I don't think
 the `update_or_create` call is necessary, we can stick to two
 `get_or_create` I think? or is there any value/difference to use one of
 each?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36489#comment:2>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070197c73a30f3-e536ec52-0950-4af7-a1ad-9672ab7de064-000000%40eu-central-1.amazonses.com.

Reply via email to