Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Russell Keith-Magee authored March 07, 2010
12  django/db/models/sql/query.py
@@ -148,7 +148,7 @@ def __str__(self):
148 148
         return sql % params
149 149
 
150 150
     def __deepcopy__(self, memo):
151  
-        result= self.clone()
  151
+        result = self.clone(memo=memo)
152 152
         memo[id(self)] = result
153 153
         return result
154 154
 
@@ -199,7 +199,7 @@ def get_meta(self):
199 199
         """
200 200
         return self.model._meta
201 201
 
202  
-    def clone(self, klass=None, **kwargs):
  202
+    def clone(self, klass=None, memo=None, **kwargs):
203 203
         """
204 204
         Creates a copy of the current instance. The 'kwargs' parameter can be
205 205
         used by clients to update attributes after copying has taken place.
@@ -223,19 +223,19 @@ def clone(self, klass=None, **kwargs):
223 223
         obj.dupe_avoidance = self.dupe_avoidance.copy()
224 224
         obj.select = self.select[:]
225 225
         obj.tables = self.tables[:]
226  
-        obj.where = deepcopy(self.where)
  226
+        obj.where = deepcopy(self.where, memo=memo)
227 227
         obj.where_class = self.where_class
228 228
         if self.group_by is None:
229 229
             obj.group_by = None
230 230
         else:
231 231
             obj.group_by = self.group_by[:]
232  
-        obj.having = deepcopy(self.having)
  232
+        obj.having = deepcopy(self.having, memo=memo)
233 233
         obj.order_by = self.order_by[:]
234 234
         obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
235 235
         obj.distinct = self.distinct
236 236
         obj.select_related = self.select_related
237 237
         obj.related_select_cols = []
238  
-        obj.aggregates = deepcopy(self.aggregates)
  238
+        obj.aggregates = deepcopy(self.aggregates, memo=memo)
239 239
         if self.aggregate_select_mask is None:
240 240
             obj.aggregate_select_mask = None
241 241
         else:
@@ -256,7 +256,7 @@ def clone(self, klass=None, **kwargs):
256 256
             obj._extra_select_cache = self._extra_select_cache.copy()
257 257
         obj.extra_tables = self.extra_tables
258 258
         obj.extra_order_by = self.extra_order_by
259  
-        obj.deferred_loading = deepcopy(self.deferred_loading)
  259
+        obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo)
260 260
         if self.filter_is_sticky and self.used_aliases:
261 261
             obj.used_aliases = self.used_aliases.copy()
262 262
         else:
7  tests/modeltests/many_to_one/models.py
@@ -263,6 +263,13 @@ class Meta:
263 263
 >>> Reporter.objects.filter(article__reporter__exact=r).distinct()
264 264
 [<Reporter: John Smith>]
265 265
 
  266
+# Regression for #12876 -- Model methods that include queries that
  267
+# recursive don't cause recursion depth problems under deepcopy.
  268
+>>> r.cached_query = Article.objects.filter(reporter=r)
  269
+>>> from copy import deepcopy
  270
+>>> deepcopy(r)
  271
+<Reporter: John Smith>
  272
+
266 273
 # Check that implied __exact also works.
267 274
 >>> Reporter.objects.filter(article__reporter=r).distinct()
268 275
 [<Reporter: John Smith>]

0 notes on commit 3508a86

Please sign in to comment.
Something went wrong with that request. Please try again.