From 5546430304f1310e76b217bb3b6e3597d9b87359 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 23 Feb 2010 05:26:49 +0000 Subject: [PATCH] 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 --- AUTHORS | 1 + django/db/models/query.py | 3 ++- tests/modeltests/aggregation/models.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index d60a9f72a5..ed27c1ede6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -289,6 +289,7 @@ answer newbie questions, and generally made Django that much better: Christopher Lenz lerouxb@gmail.com Piotr Lewandowski + Charlie Leifer Justin Lilly Waylan Limberg limodou diff --git a/django/db/models/query.py b/django/db/models/query.py index 0424569e0b..7492039b2c 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -954,7 +954,8 @@ class ValuesListQuerySet(ValuesQuerySet): # If a field list has been specified, use it. Otherwise, use the # full list of fields, including extras and aggregates. if self._fields: - fields = self._fields + fields = list(self._fields) + filter(lambda f: f not in self._fields, + aggregate_names) else: fields = names diff --git a/tests/modeltests/aggregation/models.py b/tests/modeltests/aggregation/models.py index 9ed638ea80..0e8d8816e6 100644 --- a/tests/modeltests/aggregation/models.py +++ b/tests/modeltests/aggregation/models.py @@ -362,4 +362,7 @@ True >>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values_list('mean_age', flat=True) [34.5] +>>> Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price') +[(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)] + """}