{{{
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.
* owner: (none) => Iain P. Watts
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:1>
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:3>
Comment (by Iain P. Watts):
https://github.com/django/django/pull/11369
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:4>
* version: 2.2 => master
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"59ffafa1d2f466fa7aacbe74fe2787b2004b7871" 59ffafa1]:
{{{
#!CommitTicketReference repository=""
revision="59ffafa1d2f466fa7aacbe74fe2787b2004b7871"
Fixed #30482 -- Prevented unnecessary evaluation of lookup.queryset in
prefetch_related_objects().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30482#comment:6>