#30482: prefetch_related_objects evaluates lookup.queryset when checking for
invalid prefetch ordering
-------------------------------------+-------------------------------------
               Reporter:  Iain P.    |          Owner:  (none)
  Watts                              |
                   Type:             |         Status:  assigned
  Uncategorized                      |
              Component:  Database   |        Version:  2.2
  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          |
-------------------------------------+-------------------------------------
 When encountering a prefetch it has already seen and checking whether to
 throw the "lookup was already seen with a different queryset" ValueError,
 prefetch_related_objects will inadvertently evaluate lookup.queryset. For
 example:

 {{{
 foo = Foo.objects.create()
 prefetches = [
     'bar',
     Prefetch('bar', queryset=Bar.objects.filter(my_field=True))
 ]
 prefetch_related_objects([foo], *prefetches)
 }}}
 Right before it throws the ValueError, the above code will execute the
 full unfiltered query `Bar.objects.filter(my_field=True)`. This may match
 a very large number of rows (or a whole table), since it is not restricted
 to `Bars` related to the specific `foo`. In our case this led to the query
 timing out and the page returning a 504 without the code ever actually
 reaching the ValueError.

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

Reply via email to