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/annotations/tests.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/annotations') diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 981e73e43e..1714076e1d 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -508,3 +508,12 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertIs(book.is_book, True) self.assertIs(book.is_pony, False) self.assertIsNone(book.is_none) + + def test_arguments_must_be_expressions(self): + msg = 'QuerySet.annotate() received non-expression(s): %s.' + with self.assertRaisesMessage(TypeError, msg % BooleanField()): + Book.objects.annotate(BooleanField()) + with self.assertRaisesMessage(TypeError, msg % True): + Book.objects.annotate(is_book=True) + with self.assertRaisesMessage(TypeError, msg % ', '.join([str(BooleanField()), 'True'])): + Book.objects.annotate(BooleanField(), Value(False), is_book=True) -- cgit v1.3