mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #24923 -- errored out nicely when using aggregates in order_by()
This commit is contained in:
committed by
Tim Graham
parent
83f6373030
commit
6f403056f0
@@ -105,6 +105,14 @@ class AggregateTestCase(TestCase):
|
||||
def test_empty_aggregate(self):
|
||||
self.assertEqual(Author.objects.all().aggregate(), {})
|
||||
|
||||
def test_aggregate_in_order_by(self):
|
||||
msg = (
|
||||
'Using an aggregate in order_by() without also including it in '
|
||||
'annotate() is not allowed: Avg(F(book__rating)'
|
||||
)
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
Author.objects.values('age').order_by(Avg('book__rating'))
|
||||
|
||||
def test_single_aggregate(self):
|
||||
vals = Author.objects.aggregate(Avg("age"))
|
||||
self.assertEqual(vals, {"age__avg": Approximate(37.4, places=1)})
|
||||
|
||||
Reference in New Issue
Block a user