summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-05-21 23:49:05 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-23 07:39:18 +0200
commit57f499e412c7c28b4a1f1b740468bf6eabbdb695 (patch)
treeb2e9034613da969d3b76972b054fbb9b410890d9 /tests
parentb4563cdd23ef0361588430c1f51bea819b3e0692 (diff)
[4.2.x] Refs #34551 -- Fixed QuerySet.aggregate() crash on precending aggregation reference.
Regression in 1297c0d0d76a708017fe196b61a0ab324df76954. Refs #31679. Backport of 2ee01747c32a7275a7a1a5f7862acba7db764921 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/aggregation/tests.py17
1 files changed, 11 insertions, 6 deletions
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,
+ },
)