diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-31 11:33:24 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-31 11:34:29 +0100 |
| commit | aff79be03a8c787ba0cc7e00dcec9eeb8ad01c87 (patch) | |
| tree | 8b60ea9252f26dc4d82c810beca15e0a855635b2 /tests | |
| parent | 7a1c6533eb72c3e6faa308796ba7f8d7d447d3b9 (diff) | |
[4.0.x] Fixed #33468 -- Fixed QuerySet.aggregate() after annotate() crash on aggregates with default.
Thanks Adam Johnson for the report.
Backport of 71e7c8e73712419626f1c2b6ec036e8559a2d667 from main
Diffstat (limited to 'tests')
| -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 72575a526c..68d3c4d31e 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1604,6 +1604,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'), |
