summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-05-17 11:32:30 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-19 07:52:44 +0200
commit820b4e565a06eddacf9a8038dd7b83784c6e99da (patch)
treea39c737aa53bc670e0efd593c02cc420f9b19e2b /tests
parentaa3197e5f11f33aef22f4d5a1fe711501bfbc49c (diff)
[4.1.x] Fixed #33705 -- Fixed crash when using IsNull() lookup in filters.
Thanks Florian Apolloner for the report. Thanks Simon Charette for the review. Backport of 9f5548952906c6ea97200c016734b4f519520a64 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/tests.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index 9f2e9d4b46..11a277d7e0 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -24,6 +24,7 @@ from django.db.models.lookups import (
Exact,
GreaterThan,
GreaterThanOrEqual,
+ IsNull,
LessThan,
LessThanOrEqual,
)
@@ -1284,7 +1285,7 @@ class LookupQueryingTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.s1 = Season.objects.create(year=1942, gt=1942)
- cls.s2 = Season.objects.create(year=1842, gt=1942)
+ cls.s2 = Season.objects.create(year=1842, gt=1942, nulled_text_field="text")
cls.s3 = Season.objects.create(year=2042, gt=1942)
def test_annotate(self):
@@ -1366,6 +1367,16 @@ class LookupQueryingTests(TestCase):
qs = Season.objects.filter(GreaterThan(F("year"), 1910))
self.assertCountEqual(qs, [self.s1, self.s3])
+ def test_isnull_lookup_in_filter(self):
+ self.assertSequenceEqual(
+ Season.objects.filter(IsNull(F("nulled_text_field"), False)),
+ [self.s2],
+ )
+ self.assertCountEqual(
+ Season.objects.filter(IsNull(F("nulled_text_field"), True)),
+ [self.s1, self.s3],
+ )
+
def test_filter_lookup_lhs(self):
qs = Season.objects.annotate(before_20=LessThan(F("year"), 2000)).filter(
before_20=LessThan(F("year"), 1900),