Ticket #12876: bug12876.patch

File bug12876.patch, 2.9 KB (added by elachuni, 9 years ago)

Patch with a brief doctest

  • django/db/models/sql/query.py

     
    148148        return sql % params
    149149
    150150    def __deepcopy__(self, memo):
    151         result= self.clone()
     151        result = self.clone(memo=memo)
    152152        memo[id(self)] = result
    153153        return result
    154154
     
    199199        """
    200200        return self.model._meta
    201201
    202     def clone(self, klass=None, **kwargs):
     202    def clone(self, klass=None, memo=None, **kwargs):
    203203        """
    204204        Creates a copy of the current instance. The 'kwargs' parameter can be
    205205        used by clients to update attributes after copying has taken place.
     
    223223        obj.dupe_avoidance = self.dupe_avoidance.copy()
    224224        obj.select = self.select[:]
    225225        obj.tables = self.tables[:]
    226         obj.where = deepcopy(self.where)
     226        obj.where = deepcopy(self.where, memo=memo)
    227227        obj.where_class = self.where_class
    228228        if self.group_by is None:
    229229            obj.group_by = None
    230230        else:
    231231            obj.group_by = self.group_by[:]
    232         obj.having = deepcopy(self.having)
     232        obj.having = deepcopy(self.having, memo=memo)
    233233        obj.order_by = self.order_by[:]
    234234        obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
    235235        obj.distinct = self.distinct
    236236        obj.select_related = self.select_related
    237237        obj.related_select_cols = []
    238         obj.aggregates = deepcopy(self.aggregates)
     238        obj.aggregates = deepcopy(self.aggregates, memo=memo)
    239239        if self.aggregate_select_mask is None:
    240240            obj.aggregate_select_mask = None
    241241        else:
     
    256256            obj._extra_select_cache = self._extra_select_cache.copy()
    257257        obj.extra_tables = self.extra_tables
    258258        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)
    260260        if self.filter_is_sticky and self.used_aliases:
    261261            obj.used_aliases = self.used_aliases.copy()
    262262        else:
  • tests/modeltests/many_to_one/models.py

     
    263263>>> Reporter.objects.filter(article__reporter__exact=r).distinct()
    264264[<Reporter: John Smith>]
    265265
     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
    266273# Check that implied __exact also works.
    267274>>> Reporter.objects.filter(article__reporter=r).distinct()
    268275[<Reporter: John Smith>]
Back to Top