#27499: Pickling a QuerySet evaluates the querysets given to Prefetch in
prefetch_related
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Chainz |
Type: | Status: new
Uncategorized |
Component: | Version: 1.10
Uncategorized |
Severity: Normal | Keywords: prefetch_related
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Wrote a minimal test case already for `tests/queryset_pickle/tests.py`:
{{{
def test_pickle_prefetch_related_queryset_not_evaluated(self):
Group.objects.create(name='foo')
groups = Group.objects.prefetch_related(
models.Prefetch('event_set',
queryset=Event.objects.order_by('id'))
)
list(groups) # evaluate QS
with self.assertNumQueries(0):
pickle.dumps(groups)
}}}
At current doing `pickle.dumps` evaluates `Event.objects.order_by('id')`
which is obviously a bad thing, especially if `Event` is a large table!
Found this as a kind of regression when upgrading 1.9 -> 1.10 because the
`prefetch_related` refactoring seems to be keeping the `Prefetch` objects
around more, but afaict it has always existed.
--
Ticket URL: <https://code.djangoproject.com/ticket/27499>
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/053.fd97c239cb3d2cd2c22944fd28a7f087%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.