From e0d8981139cd329962e509efb575fdfb2dad4073 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 8 May 2023 19:34:30 +0200 Subject: [4.2.x] Fixed #34544 -- Avoided DBMS_LOB.SUBSTR() wrapping with IS NULL condition on Oracle. Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca. Thanks Michael Smith for the report. This also reverts commit 1e4da439556cdd69eb9f91e07f99cf77997e70d2. Backport of 1586a09b7949bbb7b0d84cb74ce1cadc25cbb355 from main --- tests/lookup/models.py | 12 +----------- tests/lookup/tests.py | 9 ++++++++- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/lookup/models.py b/tests/lookup/models.py index 9bb3412c33..75f3e3b6ba 100644 --- a/tests/lookup/models.py +++ b/tests/lookup/models.py @@ -19,6 +19,7 @@ class Alarm(models.Model): class Author(models.Model): name = models.CharField(max_length=100) alias = models.CharField(max_length=50, null=True, blank=True) + bio = models.TextField(null=True) class Meta: ordering = ("name",) @@ -50,22 +51,11 @@ class NulledTextField(models.TextField): return None if value == "" else value -class NullField(models.Field): - pass - - -NullField.register_lookup(IsNull) - - @NulledTextField.register_lookup class NulledTransform(models.Transform): lookup_name = "nulled" template = "NULL" - @property - def output_field(self): - return NullField() - @NulledTextField.register_lookup class IsNullWithNoneAsRHS(IsNull): diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 503bae18fc..ab3d968aac 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -49,7 +49,7 @@ class LookupTests(TestCase): @classmethod def setUpTestData(cls): # Create a few Authors. - cls.au1 = Author.objects.create(name="Author 1", alias="a1") + cls.au1 = Author.objects.create(name="Author 1", alias="a1", bio="x" * 4001) cls.au2 = Author.objects.create(name="Author 2", alias="a2") # Create a few Articles. cls.a1 = Article.objects.create( @@ -1000,6 +1000,13 @@ class LookupTests(TestCase): Season.objects.create(year=2012, gt=None) self.assertQuerySetEqual(Season.objects.filter(gt__regex=r"^$"), []) + def test_textfield_exact_null(self): + with self.assertNumQueries(1) as ctx: + self.assertSequenceEqual(Author.objects.filter(bio=None), [self.au2]) + # Columns with IS NULL condition are not wrapped (except PostgreSQL). + bio_column = connection.ops.quote_name(Author._meta.get_field("bio").column) + self.assertIn(f"{bio_column} IS NULL", ctx.captured_queries[0]["sql"]) + def test_regex_non_string(self): """ A regex lookup does not fail on non-string fields -- cgit v1.3