Ticket #12876: bug12876.patch
File bug12876.patch, 2.9 KB (added by , 15 years ago) |
---|
-
django/db/models/sql/query.py
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 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 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 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: -
tests/modeltests/many_to_one/models.py
263 263 >>> Reporter.objects.filter(article__reporter__exact=r).distinct() 264 264 [<Reporter: John Smith>] 265 265 266 # You can stick a query that references a model in the model itself and then 267 # deepcopy that without having maximum recursion depth exceeded problems. 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>]