From 6e228d0b659c9779da7d392a75c7d2fbb42fb3cb Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 29 Jun 2017 18:25:36 +0200 Subject: Fixed #28277 -- Added validation of QuerySet.annotate() and aggregate() args. Thanks Tim Graham and Nick Pope for reviews. --- tests/aggregation/tests.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/aggregation') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 8cf0596347..c3f7998f60 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1186,3 +1186,12 @@ class AggregateTestCase(TestCase): ).filter(rating_or_num_awards__gt=F('num_awards')).order_by('num_awards') self.assertQuerysetEqual( qs2, [1, 3], lambda v: v.num_awards) + + def test_arguments_must_be_expressions(self): + msg = 'QuerySet.aggregate() received non-expression(s): %s.' + with self.assertRaisesMessage(TypeError, msg % FloatField()): + Book.objects.aggregate(FloatField()) + with self.assertRaisesMessage(TypeError, msg % True): + Book.objects.aggregate(is_book=True) + with self.assertRaisesMessage(TypeError, msg % ', '.join([str(FloatField()), 'True'])): + Book.objects.aggregate(FloatField(), Avg('price'), is_book=True) -- cgit v1.3