|
1 | | ---- django/db/models/query.py 2017-04-07 15:10:29.426831000 -0700 |
2 | | -+++ django/db/models/query.py 2017-04-12 08:23:20.061651277 -0700 |
| 1 | +--- /home/henrik/src/db/latest/env/lib/python2.7/site-packages/django/db/models/query.py 2018-03-13 07:07:54.156249000 -0700 |
| 2 | ++++ /home/henrik/src/db/trunk/env/lib/python2.7/site-packages/django/db/models/query.py 2018-03-14 09:06:43.378819023 -0700 |
3 | 3 | @@ -5,6 +5,7 @@ |
4 | 4 | import copy |
5 | 5 | import sys |
|
8 | 8 | from collections import OrderedDict, deque |
9 | 9 |
|
10 | 10 | from django.conf import settings |
11 | | -@@ -34,7 +35,6 @@ |
12 | | - # Pull into this namespace for backwards compatibility. |
13 | | - EmptyResultSet = sql.EmptyResultSet |
14 | | - |
15 | | -- |
16 | | - class BaseIterable(object): |
17 | | - def __init__(self, queryset): |
18 | | - self.queryset = queryset |
19 | | -@@ -51,6 +51,7 @@ |
20 | | - compiler = queryset.query.get_compiler(using=db) |
21 | | - # Execute the query. This will also fill compiler.select, klass_info, |
22 | | - # and annotations. |
23 | | -+ |
24 | | - results = compiler.execute_sql() |
25 | | - select, klass_info, annotation_col_map = (compiler.select, compiler.klass_info, |
26 | | - compiler.annotation_col_map) |
27 | | -@@ -174,6 +175,8 @@ |
28 | | - self._known_related_objects = {} # {rel_field, {pk: rel_obj}} |
| 11 | +@@ -171,6 +172,8 @@ |
| 12 | + self._known_related_objects = {} # {rel_field: {pk: rel_obj}} |
29 | 13 | self._iterable_class = ModelIterable |
30 | 14 | self._fields = None |
31 | 15 | + self._origin = [] |
32 | 16 | + self._djangodir = __file__[:(__file__.index('django')+len('django')+1)] |
33 | 17 |
|
34 | 18 | def as_manager(cls): |
35 | 19 | # Address the circular dependency between `Queryset` and `Manager`. |
36 | | -@@ -316,6 +319,31 @@ |
| 20 | +@@ -310,6 +313,31 @@ |
37 | 21 | combined.query.combine(other.query, sql.OR) |
38 | 22 | return combined |
39 | 23 |
|
|
65 | 49 | #################################### |
66 | 50 | # METHODS THAT DO DATABASE QUERIES # |
67 | 51 | #################################### |
68 | | -@@ -793,6 +821,7 @@ |
| 52 | +@@ -781,6 +809,7 @@ |
69 | 53 | Returns a new QuerySet instance with the args ANDed to the existing |
70 | 54 | set. |
71 | 55 | """ |
72 | 56 | + self._add_origin() |
73 | 57 | return self._filter_or_exclude(False, *args, **kwargs) |
74 | 58 |
|
75 | 59 | def exclude(self, *args, **kwargs): |
76 | | -@@ -800,6 +829,7 @@ |
| 60 | +@@ -788,6 +817,7 @@ |
77 | 61 | Returns a new QuerySet instance with NOT (args) ANDed to the existing |
78 | 62 | set. |
79 | 63 | """ |
80 | 64 | + self._add_origin() |
81 | 65 | return self._filter_or_exclude(True, *args, **kwargs) |
82 | 66 |
|
83 | 67 | def _filter_or_exclude(self, negate, *args, **kwargs): |
84 | | -@@ -824,6 +854,7 @@ |
| 68 | +@@ -812,6 +842,7 @@ |
85 | 69 | This exists to support framework features such as 'limit_choices_to', |
86 | 70 | and usually it will be more natural to use other methods. |
87 | 71 | """ |
88 | 72 | + self._add_origin() |
89 | 73 | if isinstance(filter_obj, Q) or hasattr(filter_obj, 'add_to_query'): |
90 | 74 | clone = self._clone() |
91 | 75 | clone.query.add_q(filter_obj) |
92 | | -@@ -836,6 +867,7 @@ |
93 | | - Returns a new QuerySet instance that will select objects with a |
94 | | - FOR UPDATE lock. |
| 76 | +@@ -866,6 +897,7 @@ |
95 | 77 | """ |
| 78 | + if nowait and skip_locked: |
| 79 | + raise ValueError('The nowait option cannot be used with skip_locked.') |
96 | 80 | + self._add_origin() |
97 | 81 | obj = self._clone() |
98 | 82 | obj._for_write = True |
99 | 83 | obj.query.select_for_update = True |
100 | | -@@ -855,6 +887,7 @@ |
| 84 | +@@ -886,6 +918,7 @@ |
101 | 85 | if self._fields is not None: |
102 | 86 | raise TypeError("Cannot call select_related() after .values() or .values_list()") |
103 | 87 |
|
104 | 88 | + self._add_origin() |
105 | 89 | obj = self._clone() |
106 | 90 | if fields == (None,): |
107 | 91 | obj.query.select_related = False |
108 | | -@@ -874,6 +907,7 @@ |
| 92 | +@@ -905,6 +938,7 @@ |
109 | 93 | prefetch is appended to. If prefetch_related(None) is called, the list |
110 | 94 | is cleared. |
111 | 95 | """ |
112 | 96 | + self._add_origin() |
113 | 97 | clone = self._clone() |
114 | 98 | if lookups == (None,): |
115 | | - clone._prefetch_related_lookups = [] |
116 | | -@@ -886,6 +920,7 @@ |
| 99 | + clone._prefetch_related_lookups = () |
| 100 | +@@ -917,6 +951,7 @@ |
117 | 101 | Return a query set in which the returned objects have been annotated |
118 | 102 | with extra data or aggregations. |
119 | 103 | """ |
120 | 104 | + self._add_origin() |
121 | 105 | annotations = OrderedDict() # To preserve ordering of args |
122 | 106 | for arg in args: |
123 | 107 | # The default_alias property may raise a TypeError, so we use |
124 | | -@@ -929,6 +964,7 @@ |
| 108 | +@@ -960,6 +995,7 @@ |
125 | 109 | """ |
126 | 110 | assert self.query.can_filter(), \ |
127 | 111 | "Cannot reorder a query once a slice has been taken." |
128 | 112 | + self._add_origin() |
129 | 113 | obj = self._clone() |
130 | 114 | obj.query.clear_ordering(force_empty=False) |
131 | 115 | obj.query.add_ordering(*field_names) |
132 | | -@@ -940,6 +976,7 @@ |
| 116 | +@@ -971,6 +1007,7 @@ |
133 | 117 | """ |
134 | 118 | assert self.query.can_filter(), \ |
135 | 119 | "Cannot create distinct fields once a slice has been taken." |
136 | 120 | + self._add_origin() |
137 | 121 | obj = self._clone() |
138 | 122 | obj.query.add_distinct_fields(*field_names) |
139 | 123 | return obj |
140 | | -@@ -951,6 +988,7 @@ |
| 124 | +@@ -982,6 +1019,7 @@ |
141 | 125 | """ |
142 | 126 | assert self.query.can_filter(), \ |
143 | 127 | "Cannot change a query once a slice has been taken" |
144 | 128 | + self._add_origin() |
145 | 129 | clone = self._clone() |
146 | 130 | clone.query.add_extra(select, select_params, where, params, tables, order_by) |
147 | 131 | return clone |
148 | | -@@ -959,6 +997,7 @@ |
| 132 | +@@ -990,6 +1028,7 @@ |
149 | 133 | """ |
150 | 134 | Reverses the ordering of the QuerySet. |
151 | 135 | """ |
152 | 136 | + self._add_origin() |
153 | 137 | clone = self._clone() |
154 | 138 | clone.query.standard_ordering = not clone.query.standard_ordering |
155 | 139 | return clone |
156 | | -@@ -973,6 +1012,7 @@ |
| 140 | +@@ -1004,6 +1043,7 @@ |
157 | 141 | """ |
158 | 142 | if self._fields is not None: |
159 | 143 | raise TypeError("Cannot call defer() after .values() or .values_list()") |
160 | 144 | + self._add_origin() |
161 | 145 | clone = self._clone() |
162 | 146 | if fields == (None,): |
163 | 147 | clone.query.clear_deferred_loading() |
164 | | -@@ -992,6 +1032,7 @@ |
| 148 | +@@ -1023,6 +1063,7 @@ |
165 | 149 | # Can only pass None to defer(), not only(), as the rest option. |
166 | 150 | # That won't stop people trying to do this, so let's be explicit. |
167 | 151 | raise TypeError("Cannot pass None as an argument to only().") |
168 | 152 | + self._add_origin() |
169 | 153 | clone = self._clone() |
170 | 154 | clone.query.add_immediate_loading(fields) |
171 | 155 | return clone |
172 | | -@@ -1078,6 +1119,7 @@ |
| 156 | +@@ -1109,6 +1150,7 @@ |
173 | 157 | clone._known_related_objects = self._known_related_objects |
174 | 158 | clone._iterable_class = self._iterable_class |
175 | 159 | clone._fields = self._fields |
176 | 160 | + clone._origin = self._origin |
177 | 161 |
|
178 | 162 | clone.__dict__.update(kwargs) |
179 | 163 | return clone |
180 | | -@@ -1085,6 +1127,8 @@ |
| 164 | +@@ -1116,6 +1158,8 @@ |
181 | 165 | def _fetch_all(self): |
182 | 166 | if self._result_cache is None: |
183 | | - self._result_cache = list(self.iterator()) |
| 167 | + self._result_cache = list(self._iterable_class(self)) |
184 | 168 | + if settings.DEBUG: |
185 | 169 | + connections[self.db].queries_log[-1]['origin'] = self._origin |
186 | 170 | if self._prefetch_related_lookups and not self._prefetch_done: |
|
0 commit comments