Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12608 -- No longer return inconsistent results when us…

…ing values and values_list in conjunction with annotate. Thanks, Charlie Leifer.

Backport of r12505 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12613 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 499c7155132bf27479447d147053f619624a71ad 1 parent 7c23a53
Justin Bronn authored February 26, 2010
2  django/db/models/query.py
@@ -871,6 +871,8 @@ def iterator(self):
871 871
             # full list of fields, including extras and aggregates.
872 872
             if self._fields:
873 873
                 fields = self._fields
  874
+                fields = list(self._fields) + filter(lambda f: f not in self._fields,
  875
+                                                     aggregate_names)
874 876
             else:
875 877
                 fields = names
876 878
 
3  tests/modeltests/aggregation/models.py
@@ -362,4 +362,7 @@ def __unicode__(self):
362 362
 >>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values_list('mean_age', flat=True)
363 363
 [34.5]
364 364
 
  365
+>>> qs = Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')
  366
+>>> list(qs) == [(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)]
  367
+True
365 368
 """}

0 notes on commit 499c715

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