Code

Ticket #16759: 16759_cleaned_up_where_clone.diff

File 16759_cleaned_up_where_clone.diff, 3.4 KB (added by Suor, 3 years ago)

cleaned up diffrent approach

Line 
1Index: django/db/models/sql/aggregates.py
2===================================================================
3--- django/db/models/sql/aggregates.py  (revision 16928)
4+++ django/db/models/sql/aggregates.py  (working copy)
5@@ -69,6 +69,9 @@
6 
7         self.field = tmp
8 
9+    def clone(self):
10+        return self
11+
12     def relabel_aliases(self, change_map):
13         if isinstance(self.col, (list, tuple)):
14             self.col = (change_map.get(self.col[0], self.col[0]), self.col[1])
15Index: django/db/models/sql/where.py
16===================================================================
17--- django/db/models/sql/where.py       (revision 16928)
18+++ django/db/models/sql/where.py       (working copy)
19@@ -260,6 +260,9 @@
20     def relabel_aliases(self, change_map, node=None):
21         return
22 
23+    def clone(self):
24+        return self
25+
26 class NothingNode(object):
27     """
28     A node that matches nothing.
29@@ -270,6 +273,9 @@
30     def relabel_aliases(self, change_map, node=None):
31         return
32 
33+    def clone(self):
34+        return self
35+
36 class ExtraWhere(object):
37     def __init__(self, sqls, params):
38         self.sqls = sqls
39@@ -278,6 +284,9 @@
40     def as_sql(self, qn=None, connection=None):
41         return " AND ".join(self.sqls), tuple(self.params or ())
42 
43+    def clone(self):
44+        return self
45+
46 class Constraint(object):
47     """
48     An object that can be passed to WhereNode.add() and knows how to
49@@ -342,3 +351,6 @@
50     def relabel_aliases(self, change_map):
51         if self.alias in change_map:
52             self.alias = change_map[self.alias]
53+
54+    def clone(self):
55+        return Constraint(self.alias, self.col, self.field)
56Index: django/db/models/sql/query.py
57===================================================================
58--- django/db/models/sql/query.py       (revision 16928)
59+++ django/db/models/sql/query.py       (working copy)
60@@ -254,13 +254,13 @@
61         obj.dupe_avoidance = self.dupe_avoidance.copy()
62         obj.select = self.select[:]
63         obj.tables = self.tables[:]
64-        obj.where = copy.deepcopy(self.where, memo=memo)
65+        obj.where = self.where.clone()
66         obj.where_class = self.where_class
67         if self.group_by is None:
68             obj.group_by = None
69         else:
70             obj.group_by = self.group_by[:]
71-        obj.having = copy.deepcopy(self.having, memo=memo)
72+        obj.having = self.having.clone()
73         obj.order_by = self.order_by[:]
74         obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
75         obj.distinct = self.distinct
76Index: django/utils/tree.py
77===================================================================
78--- django/utils/tree.py        (revision 16928)
79+++ django/utils/tree.py        (working copy)
80@@ -45,6 +45,19 @@
81         return obj
82     _new_instance = classmethod(_new_instance)
83 
84+    def clone(self):
85+        clone = self.__class__._new_instance(
86+            children=[], connector=self.connector, negated=self.negated)
87+        for child in self.children:
88+            if isinstance(child, tuple):
89+                clone.children.append(
90+                    (child[0].clone(), child[1], child[2], child[3]))
91+            else:
92+                clone.children.append(child.clone())
93+        for parent in self.subtree_parents:
94+            clone.subtree_parents.append(parent.clone())
95+        return clone
96+
97     def __str__(self):
98         if self.negated:
99             return '(NOT (%s: %s))' % (self.connector, ', '.join([str(c) for c