mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #34544 -- Avoided DBMS_LOB.SUBSTR() wrapping with IS NULL condition on Oracle.
Regression in09ffc5c121. Thanks Michael Smith for the report. This also reverts commit1e4da43955.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
@@ -1029,6 +1029,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
|
||||
|
||||
Reference in New Issue
Block a user