Code

Ticket #7256: extra_values.diff

File extra_values.diff, 1.3 KB (added by nicolas, 6 years ago)
Line 
1Index: django/db/models/query.py
2===================================================================
3--- django/db/models/query.py   (revision 7616)
4+++ django/db/models/query.py   (working copy)
5@@ -513,7 +513,9 @@
6         # names of the model fields to select.
7 
8     def iterator(self):
9-        self.query.trim_extra_select(self.extra_names)
10+        if (not self.extra_names and
11+            len(self.field_names) != len(self.model._meta.fields)):
12+            self.query.trim_extra_select(self.extra_names)
13         names = self.query.extra_select.keys() + self.field_names
14         for row in self.query.results_iter():
15             yield dict(zip(names, row))
16Index: tests/regressiontests/queries/models.py
17===================================================================
18--- tests/regressiontests/queries/models.py     (revision 7616)
19+++ tests/regressiontests/queries/models.py     (working copy)
20@@ -507,6 +507,10 @@
21 >>> [sorted(d.items()) for d in dicts]
22 [[('id', 1), ('rank', 2)], [('id', 2), ('rank', 1)], [('id', 3), ('rank', 3)]]
23 
24+# But an empty values() call includes all aliases.
25+>>> qs.values().order_by('id')
26+[{'author_id': 2, 'good': 0, 'id': 1, 'rank': 2}, {'author_id': 3, 'good': 0, 'id': 2, 'rank': 1}, {'author_id': 1, 'good': 1, 'id': 3, 'rank': 3}]
27+
28 Bugs #2874, #3002
29 >>> qs = Item.objects.select_related().order_by('note__note', 'name')
30 >>> list(qs)