diff options
| author | Simon Charette <charettes@users.noreply.github.com> | 2019-01-21 08:24:32 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-01-21 09:24:47 -0500 |
| commit | 6516e49262546238d02f6ca37b74ee0e67dead0a (patch) | |
| tree | 1fa4892a126e58025dbbfeb9a1e8a2de67022a73 /tests | |
| parent | 370371ee9e0b2f47fa9735310c3a784714c61291 (diff) | |
[2.2.x] Fixed #30120 -- Fixed invalid SQL in distinct aggregate.
Regression in bc05547cd8c1dd511c6b6a6c873a1bc63417b111 (refs #28658).
Backport of 65858119d23e37872505a4476e7141c33981fb50 from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 8cac90f020..3820496c9f 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -8,6 +8,7 @@ from django.db.models import ( Avg, Count, DecimalField, DurationField, F, FloatField, Func, IntegerField, Max, Min, Sum, Value, ) +from django.db.models.expressions import Case, When from django.test import TestCase from django.test.utils import Approximate, CaptureQueriesContext from django.utils import timezone @@ -395,6 +396,12 @@ class AggregateTestCase(TestCase): sql = ctx.captured_queries[0]['sql'] self.assertIn('SELECT COUNT(*) ', sql) + def test_count_distinct_expression(self): + aggs = Book.objects.aggregate( + distinct_ratings=Count(Case(When(pages__gt=300, then='rating')), distinct=True), + ) + self.assertEqual(aggs['distinct_ratings'], 4) + def test_non_grouped_annotation_not_in_group_by(self): """ An annotation not included in values() before an aggregate should be |
