1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

[4.2.x] Refs #34551 -- Fixed QuerySet.aggregate() crash on precending aggregation reference.

Regression in 1297c0d0d7.

Refs #31679.

Backport of 2ee01747c3 from main
This commit is contained in:
Simon Charette
2023-05-21 23:49:05 -04:00
committed by Mariusz Felisiak
parent b4563cdd23
commit 57f499e412
4 changed files with 37 additions and 9 deletions

View File

@@ -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,
},
)