From 9c9a3fe1180fc92fbd4c3302dbe0b3e083bf0381 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 28 Jul 2020 13:56:39 +0200 Subject: Fixed #31783 -- Fixed crash when filtering againts "negate" field. Thanks Simon Charette for the initial patch. --- tests/queries/models.py | 1 + tests/queries/tests.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/queries/models.py b/tests/queries/models.py index a4f6245aa8..a5faa2a84b 100644 --- a/tests/queries/models.py +++ b/tests/queries/models.py @@ -42,6 +42,7 @@ class Note(models.Model): note = models.CharField(max_length=100) misc = models.CharField(max_length=10) tag = models.ForeignKey(Tag, models.SET_NULL, blank=True, null=True) + negate = models.BooleanField(default=True) class Meta: ordering = ['note'] diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 2863cfb568..f9a57b088a 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -47,7 +47,7 @@ class Queries1Tests(TestCase): cls.n1 = Note.objects.create(note='n1', misc='foo', id=1) cls.n2 = Note.objects.create(note='n2', misc='bar', id=2) - cls.n3 = Note.objects.create(note='n3', misc='foo', id=3) + cls.n3 = Note.objects.create(note='n3', misc='foo', id=3, negate=False) ann1 = Annotation.objects.create(name='a1', tag=cls.t1) ann1.notes.add(cls.n1) @@ -1216,6 +1216,13 @@ class Queries1Tests(TestCase): [self.a3, self.a4], ) + def test_negate_field(self): + self.assertSequenceEqual( + Note.objects.filter(negate=True), + [self.n1, self.n2], + ) + self.assertSequenceEqual(Note.objects.exclude(negate=True), [self.n3]) + class Queries2Tests(TestCase): @classmethod -- cgit v1.3