Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7256 -- Corrected queryset code to return the correct set of c…

…olumns when the query has an empty values() clause as well as extra selects from an extra() clause. Thanks to Nicolas Lara for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7636 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 57311b5998900da5a320b9fde7605c834bc0db15 1 parent 0b8fafc
Russell Keith-Magee authored June 15, 2008
4  django/db/models/query.py
@@ -513,7 +513,9 @@ def __init__(self, *args, **kwargs):
513 513
         # names of the model fields to select.
514 514
 
515 515
     def iterator(self):
516  
-        self.query.trim_extra_select(self.extra_names)
  516
+        if (not self.extra_names and 
  517
+            len(self.field_names) != len(self.model._meta.fields)):
  518
+            self.query.trim_extra_select(self.extra_names)
517 519
         names = self.query.extra_select.keys() + self.field_names
518 520
         for row in self.query.results_iter():
519 521
             yield dict(zip(names, row))
6  tests/regressiontests/queries/models.py
@@ -507,6 +507,12 @@ def __unicode__(self):
507 507
 >>> [sorted(d.items()) for d in dicts]
508 508
 [[('id', 1), ('rank', 2)], [('id', 2), ('rank', 1)], [('id', 3), ('rank', 3)]]
509 509
 
  510
+Bug #7256
  511
+# An empty values() call includes all aliases, including those from an extra()
  512
+>>> dicts = qs.values().order_by('id')
  513
+>>> [sorted(d.items()) for d in dicts]
  514
+[[('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)]]
  515
+
510 516
 Bugs #2874, #3002
511 517
 >>> qs = Item.objects.select_related().order_by('note__note', 'name')
512 518
 >>> list(qs)

0 notes on commit 57311b5

Please sign in to comment.
Something went wrong with that request. Please try again.