diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-31 11:33:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-31 11:33:24 +0100 |
| commit | 71e7c8e73712419626f1c2b6ec036e8559a2d667 (patch) | |
| tree | 0e6b7ad62e5d92b48e4ef3d13103d182d9ad1d22 /tests/aggregation | |
| parent | beb7ddbcee03270e833b2f74927ccfc8027aa693 (diff) | |
Fixed #33468 -- Fixed QuerySet.aggregate() after annotate() crash on aggregates with default.
Thanks Adam Johnson for the report.
Diffstat (limited to 'tests/aggregation')
| -rw-r--r-- | tests/aggregation/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 87ae945a7e..5c9aa5d534 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1630,6 +1630,18 @@ class AggregateTestCase(TestCase): ) self.assertAlmostEqual(result['value'], Decimal('61.72'), places=2) + def test_aggregation_default_after_annotation(self): + result = Publisher.objects.annotate( + double_num_awards=F('num_awards') * 2, + ).aggregate(value=Sum('double_num_awards', default=0)) + self.assertEqual(result['value'], 40) + + def test_aggregation_default_not_in_aggregate(self): + result = Publisher.objects.annotate( + avg_rating=Avg('book__rating', default=2.5), + ).aggregate(Sum('num_awards')) + self.assertEqual(result['num_awards__sum'], 20) + def test_exists_none_with_aggregate(self): qs = Book.objects.all().annotate( count=Count('id'), |
