From 57f499e412c7c28b4a1f1b740468bf6eabbdb695 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 21 May 2023 23:49:05 -0400 Subject: [4.2.x] Refs #34551 -- Fixed QuerySet.aggregate() crash on precending aggregation reference. Regression in 1297c0d0d76a708017fe196b61a0ab324df76954. Refs #31679. Backport of 2ee01747c32a7275a7a1a5f7862acba7db764921 from main --- tests/aggregation/tests.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index ae68c24563..5135458668 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1260,7 +1260,7 @@ class AggregateTestCase(TestCase): self.assertEqual(author.sum_age, other_author.sum_age) def test_aggregate_over_aggregate(self): - msg = "Cannot resolve keyword 'age_agg' into field." + msg = "Cannot compute Avg('age_agg'): 'age_agg' is an aggregate" with self.assertRaisesMessage(FieldError, msg): Author.objects.aggregate( age_agg=Sum(F("age")), @@ -2102,12 +2102,17 @@ class AggregateTestCase(TestCase): ) self.assertEqual(len(qs), 6) - def test_aggregation_over_annotation_shared_alias(self): + def test_multiple_aggregate_references(self): + aggregates = Author.objects.aggregate( + total_books=Count("book"), + coalesced_total_books=Coalesce("total_books", 0), + ) self.assertEqual( - Publisher.objects.annotate(agg=Count("book__authors")).aggregate( - agg=Count("agg"), - ), - {"agg": 5}, + aggregates, + { + "total_books": 10, + "coalesced_total_books": 10, + }, ) -- cgit v1.3