summaryrefslogtreecommitdiff
path: root/tests/aggregation
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-01-31 11:33:24 +0100
committerGitHub <noreply@github.com>2022-01-31 11:33:24 +0100
commit71e7c8e73712419626f1c2b6ec036e8559a2d667 (patch)
tree0e6b7ad62e5d92b48e4ef3d13103d182d9ad1d22 /tests/aggregation
parentbeb7ddbcee03270e833b2f74927ccfc8027aa693 (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.py12
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'),