#27403: prefetch_related doesn't guarantee transactional consistency
-------------------------------------+-------------------------------------
               Reporter:  Aymeric    |          Owner:  nobody
  Augustin                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Let's assume a `Parent` model and a `Child` model with a FK to `Parent`.

 Database initially looks like this:
 {{{
 parent1 -- child1
 }}}

 User runs `Parent.objects.all().prefetch_related('child_set')`.

 Django fetches `parent1`.

 Another transaction commits, resulting in this structure:
 {{{
 parent1 +- child1
         `- child2
 parent2
 }}}

 Django fetches all children pointing to `parent1`, which returns `child1`
 and `child2`.

 The result of the query is:
 {{{
 parent1 +- child1
         `- child2
 }}}

 But at no point in the history did the database look like this.

 This bug report is based on code inspection.

 I verified that `prefetch_related` doesn't start a transaction.

 However I didn't write code exhibiting the race condition because that's a
 bit complicated.

--
Ticket URL: <https://code.djangoproject.com/ticket/27403>
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/052.da26f2bbf233a95ac24e6749515421c6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to