Permalink
Browse files

Fixed #10796 -- Corrected a pickling problem introduced by [10522]. T…

…hanks to carljm for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 945b89e commit 4a4d3e213316ea39a0f8d596c9c0d3dfba8ce495 @freakboy3742 freakboy3742 committed Apr 11, 2009
Showing with 11 additions and 3 deletions.
  1. +11 −3 django/db/models/sql/query.py
@@ -124,16 +124,24 @@ def __getstate__(self):
obj_dict['related_select_cols'] = []
del obj_dict['connection']
- # Fields can't be pickled, so we pickle the list of field names instead.
- obj_dict['select_fields'] = [f.name for f in obj_dict['select_fields']]
+ # Fields can't be pickled, so if a field list has been
+ # specified, we pickle the list of field names instead.
+ # None is also a possible value; that can pass as-is
+ obj_dict['select_fields'] = [
+ f is not None and f.name or None
+ for f in obj_dict['select_fields']
+ ]
return obj_dict
def __setstate__(self, obj_dict):
"""
Unpickling support.
"""
# Rebuild list of field instances
- obj_dict['select_fields'] = [obj_dict['model']._meta.get_field(name) for name in obj_dict['select_fields']]
+ obj_dict['select_fields'] = [
+ name is not None and obj_dict['model']._meta.get_field(name) or None
+ for name in obj_dict['select_fields']
+ ]
self.__dict__.update(obj_dict)
# XXX: Need a better solution for this when multi-db stuff is

0 comments on commit 4a4d3e2

Please sign in to comment.