mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #31880 -- Made QuerySet.aggregate() raise FieldError when aggregating over aggregation aliases.
This commit is contained in:
parent
01a7af09b9
commit
058747b77a
2 changed files with 20 additions and 2 deletions
|
@ -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'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue