mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #28277 -- Added validation of QuerySet.annotate() and aggregate() args.
Thanks Tim Graham and Nick Pope for reviews.
This commit is contained in:
parent
f7f5edd50d
commit
6e228d0b65
3 changed files with 31 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue