diff options
author | David Wobrock <david.wobrock@gmail.com> | 2020-09-27 15:47:27 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-09-29 09:04:25 +0200 |
commit | 058747b77a3e6710301138b8ab3bc4256077fdfa (patch) | |
tree | b3a28c7f2e9b0ff7577bef8e5842b8d9329b8d6c /tests/aggregation | |
parent | 01a7af09b9d61aa66f5bf345fc32cc8f90ecb62a (diff) | |
download | django-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.py | 10 |
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')) |