Skip to content

Commit 5546430

Browse files
committed
Fixed #12608 -- No longer return inconsistent results when using values and values_list in conjunction with annotate. Thanks, Charlie Leifer.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12505 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent c4699b0 commit 5546430

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ answer newbie questions, and generally made Django that much better:
289289
Christopher Lenz <http://www.cmlenz.net/>
290290
291291
Piotr Lewandowski <[email protected]>
292+
Charlie Leifer <[email protected]>
292293
Justin Lilly <[email protected]>
293294
Waylan Limberg <[email protected]>
294295
limodou

django/db/models/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ def iterator(self):
954954
# If a field list has been specified, use it. Otherwise, use the
955955
# full list of fields, including extras and aggregates.
956956
if self._fields:
957-
fields = self._fields
957+
fields = list(self._fields) + filter(lambda f: f not in self._fields,
958+
aggregate_names)
958959
else:
959960
fields = names
960961

tests/modeltests/aggregation/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,7 @@ def __unicode__(self):
362362
>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values_list('mean_age', flat=True)
363363
[34.5]
364364
365+
>>> Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')
366+
[(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)]
367+
365368
"""}

0 commit comments

Comments
 (0)