summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/datastructures.py2
-rw-r--r--django/db/models/sql/subqueries.py17
2 files changed, 18 insertions, 1 deletions
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index cb54a564f8..913d8fde25 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -85,7 +85,7 @@ class Date(object):
def __init__(self, col, lookup_type, date_sql_func):
self.col = col
self.lookup_type = lookup_type
- self.date_sql_func= date_sql_func
+ self.date_sql_func = date_sql_func
def relabel_aliases(self, change_map):
c = self.col
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index 5ca041cbde..cea2a58d39 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -343,6 +343,23 @@ class DateQuery(Query):
date field. This requires some special handling when converting the results
back to Python objects, so we put it in a separate class.
"""
+ def __getstate__(self):
+ """
+ Special DateQuery-specific pickle handling.
+ """
+ for elt in self.select:
+ if isinstance(elt, Date):
+ # Eliminate a method reference that can't be pickled. The
+ # __setstate__ method restores this.
+ elt.date_sql_func = None
+ return super(DateQuery, self).__getstate__()
+
+ def __setstate__(self, obj_dict):
+ super(DateQuery, self).__setstate__(obj_dict)
+ for elt in self.select:
+ if isinstance(elt, Date):
+ self.date_sql_func = self.connection.ops.date_trunc_sql
+
def results_iter(self):
"""
Returns an iterator over the results from executing this query.