From bac187c0d8e829fb3ca2ca82965eabbcbcb6ddd5 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Tue, 21 May 2013 11:06:49 +0300 Subject: [1.5.x] Fixed prefetch_related + pickle regressions There were a couple of regressions related to field pickling. The regressions were introduced by QuerySet._known_related_objects caching. The regressions aren't present in master, the fix was likely in f403653cf146384946e5c879ad2a351768ebc226. Fixed #20157, fixed #20257. Also made QuerySets with model=None picklable. --- django/db/models/sql/query.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 7368fed24c..390444d799 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -208,12 +208,17 @@ class Query(object): Unpickling support. """ # Rebuild list of field instances - opts = obj_dict['model']._meta - obj_dict['select_fields'] = [ - name is not None and opts.get_field(name) or None - for name in obj_dict['select_fields'] - ] - + model = obj_dict['model'] + if model is None: + # if model is None the queryset should be emptyqs. So the + # select_fields do not matter. + obj_dict['select_fields'] = [] + else: + opts = model._meta + obj_dict['select_fields'] = [ + name is not None and opts.get_field(name) or None + for name in obj_dict['select_fields'] + ] self.__dict__.update(obj_dict) def prepare(self): -- cgit v1.3