summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-22 06:01:11 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-22 06:07:19 +0200
commita148461f1fa7aceb2ea6c9dc203b67a170884445 (patch)
treed5e26bde657abb0565bb750f58347ae831f63b6d /django
parentb08f53ff46238301431084b50762a40170d7869d (diff)
[4.2.x] Fixed #34840 -- Avoided casting string base fields on PostgreSQL.
Thanks Alex Vandiver for the report. Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca. Backport of 779cd28acb1f7eb06f629c0ea4ded99b5ebb670a from main.
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/postgresql/operations.py11
-rw-r--r--django/db/models/lookups.py12
2 files changed, 8 insertions, 15 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 18cfcb29cb..c4d90b56ab 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -153,17 +153,6 @@ class DatabaseOperations(BaseDatabaseOperations):
def lookup_cast(self, lookup_type, internal_type=None):
lookup = "%s"
-
- if lookup_type == "isnull" and internal_type in (
- "CharField",
- "EmailField",
- "TextField",
- "CICharField",
- "CIEmailField",
- "CITextField",
- ):
- return "%s::text"
-
# Cast text lookups to text to allow things like filter(x__contains=4)
if lookup_type in (
"iexact",
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index d3697b2003..a4729c640a 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -568,11 +568,15 @@ class IsNull(BuiltinLookup):
raise ValueError(
"The QuerySet value for an isnull lookup must be True or False."
)
- if isinstance(self.lhs, Value) and self.lhs.value is None:
- if self.rhs:
- raise FullResultSet
+ if isinstance(self.lhs, Value):
+ if self.lhs.value is None or (
+ self.lhs.value == ""
+ and connection.features.interprets_empty_strings_as_nulls
+ ):
+ result_exception = FullResultSet if self.rhs else EmptyResultSet
else:
- raise EmptyResultSet
+ result_exception = EmptyResultSet if self.rhs else FullResultSet
+ raise result_exception
sql, params = self.process_lhs(compiler, connection)
if self.rhs:
return "%s IS NULL" % sql, params