diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 4b758e7adc..42a4b054a5 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -183,9 +183,6 @@ class WhereNode(tree.Node): clone.relabel_aliases(change_map) return clone - def copy(self): - return self.clone() - @classmethod def _contains_aggregate(cls, obj): if isinstance(obj, tree.Node): diff --git a/django/utils/tree.py b/django/utils/tree.py index 7ee5b01444..d897cbeacd 100644 --- a/django/utils/tree.py +++ b/django/utils/tree.py @@ -44,6 +44,13 @@ class Node: def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, self) + def __copy__(self): + obj = self.create(connector=self.connector, negated=self.negated) + obj.children = self.children # Don't [:] as .__init__() via .create() does. + return obj + + copy = __copy__ + def __deepcopy__(self, memodict): obj = self.create(connector=self.connector, negated=self.negated) obj.children = copy.deepcopy(self.children, memodict)