summaryrefslogtreecommitdiff
path: root/tests/aggregation
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2020-09-27 15:47:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-29 09:04:25 +0200
commit058747b77a3e6710301138b8ab3bc4256077fdfa (patch)
treeb3a28c7f2e9b0ff7577bef8e5842b8d9329b8d6c /tests/aggregation
parent01a7af09b9d61aa66f5bf345fc32cc8f90ecb62a (diff)
downloaddjango-058747b77a3e6710301138b8ab3bc4256077fdfa.tar.gz
Fixed #31880 -- Made QuerySet.aggregate() raise FieldError when aggregating over aggregation aliases.
Diffstat (limited to 'tests/aggregation')
-rw-r--r--tests/aggregation/tests.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 1f6baa70ff..f8aeceb2d0 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1004,6 +1004,16 @@ class AggregateTestCase(TestCase):
self.assertEqual(author.sum_age, other_author.sum_age)
+ def test_aggregate_over_aggregate(self):
+ msg = "Cannot compute Avg('age'): 'age' is an aggregate"
+ with self.assertRaisesMessage(FieldError, msg):
+ Author.objects.annotate(
+ age_alias=F('age'),
+ ).aggregate(
+ age=Sum(F('age')),
+ avg_age=Avg(F('age')),
+ )
+
def test_annotated_aggregate_over_annotated_aggregate(self):
with self.assertRaisesMessage(FieldError, "Cannot compute Sum('id__max'): 'id__max' is an aggregate"):
Book.objects.annotate(Max('id')).annotate(Sum('id__max'))