Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12876 -- Corrected a problem with recursive relations under de…

…epcopy. Thanks to elachuni for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12700 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3508a86ddf86da7a6b1444f89217e45b3514c722 1 parent 5beb5f7
@freakboy3742 freakboy3742 authored
View
12 django/db/models/sql/query.py
@@ -148,7 +148,7 @@ def __str__(self):
return sql % params
def __deepcopy__(self, memo):
- result= self.clone()
+ result = self.clone(memo=memo)
memo[id(self)] = result
return result
@@ -199,7 +199,7 @@ def get_meta(self):
"""
return self.model._meta
- def clone(self, klass=None, **kwargs):
+ def clone(self, klass=None, memo=None, **kwargs):
"""
Creates a copy of the current instance. The 'kwargs' parameter can be
used by clients to update attributes after copying has taken place.
@@ -223,19 +223,19 @@ def clone(self, klass=None, **kwargs):
obj.dupe_avoidance = self.dupe_avoidance.copy()
obj.select = self.select[:]
obj.tables = self.tables[:]
- obj.where = deepcopy(self.where)
+ obj.where = deepcopy(self.where, memo=memo)
obj.where_class = self.where_class
if self.group_by is None:
obj.group_by = None
else:
obj.group_by = self.group_by[:]
- obj.having = deepcopy(self.having)
+ obj.having = deepcopy(self.having, memo=memo)
obj.order_by = self.order_by[:]
obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
obj.distinct = self.distinct
obj.select_related = self.select_related
obj.related_select_cols = []
- obj.aggregates = deepcopy(self.aggregates)
+ obj.aggregates = deepcopy(self.aggregates, memo=memo)
if self.aggregate_select_mask is None:
obj.aggregate_select_mask = None
else:
@@ -256,7 +256,7 @@ def clone(self, klass=None, **kwargs):
obj._extra_select_cache = self._extra_select_cache.copy()
obj.extra_tables = self.extra_tables
obj.extra_order_by = self.extra_order_by
- obj.deferred_loading = deepcopy(self.deferred_loading)
+ obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo)
if self.filter_is_sticky and self.used_aliases:
obj.used_aliases = self.used_aliases.copy()
else:
View
7 tests/modeltests/many_to_one/models.py
@@ -263,6 +263,13 @@ class Meta:
>>> Reporter.objects.filter(article__reporter__exact=r).distinct()
[<Reporter: John Smith>]
+# Regression for #12876 -- Model methods that include queries that
+# recursive don't cause recursion depth problems under deepcopy.
+>>> r.cached_query = Article.objects.filter(reporter=r)
+>>> from copy import deepcopy
+>>> deepcopy(r)
+<Reporter: John Smith>
+
# Check that implied __exact also works.
>>> Reporter.objects.filter(article__reporter=r).distinct()
[<Reporter: John Smith>]
Please sign in to comment.
Something went wrong with that request. Please try again.