1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #20782 -- qs.values().aggregate() failure

In the combination of .values().aggregate() the aggregate_select_mask
didn't include the aggregates added. This resulted in bogus query.

Thanks to Trac alias debanshuk for report.
This commit is contained in:
Anssi Kääriäinen
2013-07-23 11:38:38 +03:00
parent 29a09b3638
commit 4bd5554721
3 changed files with 19 additions and 1 deletions

View File

@@ -585,3 +585,14 @@ class BaseAggregateTestCase(TestCase):
"datetime.date(2008, 1, 1)"
]
)
def test_values_aggregation(self):
# Refs #20782
max_rating = Book.objects.values('rating').aggregate(max_rating=Max('rating'))
self.assertEqual(max_rating['max_rating'], 5)
max_books_per_rating = Book.objects.values('rating').annotate(
books_per_rating=Count('id')
).aggregate(Max('books_per_rating'))
self.assertEqual(
max_books_per_rating,
{'books_per_rating__max': 3})