Opened 8 years ago
Closed 8 years ago
#27499 closed Bug (fixed)
Pickling a QuerySet evaluates the querysets given to Prefetch in prefetch_related
Reported by: | Adam Johnson | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.10 |
Severity: | Normal | Keywords: | prefetch_related |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (5)
comment:1 by , 8 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 8 years ago
Has patch: | set |
---|
comment:3 by , 8 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
PR: https://github.com/django/django/pull/7567