diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2020-11-17 23:31:58 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-11-19 21:00:04 +0100 |
| commit | fe9c7ded2996364f853c524b4421274717d89d5f (patch) | |
| tree | b68109762bf31f99acece12b7098b9796fd9999e /tests/annotations | |
| parent | ead37dfb580136cc27dbd487a1f1ad90c9235d15 (diff) | |
Fixed #32200 -- Fixed grouping by ExpressionWrapper() with Q objects.
Thanks Gordon Wrigley for the report.
Regression in df32fd42b84cc6dbba173201f244491b0d154a63.
Diffstat (limited to 'tests/annotations')
| -rw-r--r-- | tests/annotations/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 5bd7d572df..f8346d801e 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -195,6 +195,18 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertEqual(book.isnull_pubdate, False) self.assertEqual(book.rating_count, 1) + @skipUnlessDBFeature('supports_boolean_expr_in_select_clause') + def test_grouping_by_q_expression_annotation(self): + authors = Author.objects.annotate( + under_40=ExpressionWrapper(Q(age__lt=40), output_field=BooleanField()), + ).values('under_40').annotate( + count_id=Count('id'), + ).values('under_40', 'count_id') + self.assertCountEqual(authors, [ + {'under_40': False, 'count_id': 3}, + {'under_40': True, 'count_id': 6}, + ]) + def test_aggregate_over_annotation(self): agg = Author.objects.annotate(other_age=F('age')).aggregate(otherage_sum=Sum('other_age')) other_agg = Author.objects.aggregate(age_sum=Sum('age')) |
