diff options
| author | Anssi Kääriäinen <anssi.kaariainen@thl.fi> | 2015-03-04 14:56:20 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-09 07:49:23 -0400 |
| commit | fb146193c49e4c683dc8da39d9b7c479375fdb57 (patch) | |
| tree | 1b28e5c96867ac0f0b8da1e49987ebbf25f29cc7 /tests/aggregation_regress | |
| parent | 63f2dd4ad774d39fc7bbe05492d30efc45e4e7a9 (diff) | |
Fixed #24171 -- Fixed failure with complex aggregate query and expressions
The query used a construct of qs.annotate().values().aggregate() where
the first annotate used an F-object reference and the values() and
aggregate() calls referenced that F-object.
Also made sure the inner query's select clause is as simple as possible,
and made sure .values().distinct().aggreate() works correctly.
Diffstat (limited to 'tests/aggregation_regress')
| -rw-r--r-- | tests/aggregation_regress/tests.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index a0038945fa..bfd202fbc9 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -7,7 +7,9 @@ from operator import attrgetter from django.contrib.contenttypes.models import ContentType from django.core.exceptions import FieldError -from django.db.models import F, Q, Avg, Count, Max, StdDev, Sum, Variance +from django.db.models import ( + F, Q, Avg, Count, Max, StdDev, Sum, Value, Variance, +) from django.test import TestCase, skipUnlessDBFeature from django.test.utils import Approximate from django.utils import six @@ -1232,6 +1234,14 @@ class AggregationTests(TestCase): ) self.assertEqual(qs['publisher_awards'], 30) + def test_annotate_distinct_aggregate(self): + # There are three books with rating of 4.0 and two of the books have + # the same price. Hence, the distinct removes one rating of 4.0 + # from the results. + vals1 = Book.objects.values('rating', 'price').distinct().aggregate(result=Sum('rating')) + vals2 = Book.objects.aggregate(result=Sum('rating') - Value(4.0)) + self.assertEqual(vals1, vals2) + class JoinPromotionTests(TestCase): def test_ticket_21150(self): |
