﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27499	Pickling a QuerySet evaluates the querysets given to Prefetch in prefetch_related	Adam Johnson	nobody	"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."	Bug	closed	Database layer (models, ORM)	1.10	Normal	fixed	prefetch_related		Ready for checkin	1	0	0	0	0	0
