[5.0.x] Fixed #34840 -- Avoided casting string base fields on PostgreSQL.

Thanks Alex Vandiver for the report.

Regression in 09ffc5c121.

Backport of 779cd28acb from main.
This commit is contained in:
Mariusz Felisiak 2023-09-22 06:01:11 +02:00
parent fb5dd118e9
commit 2566f92544
6 changed files with 78 additions and 15 deletions

View file

@ -376,6 +376,20 @@ class Tests(TestCase):
"::citext", do.lookup_cast(lookup, internal_type=field_type)
)
def test_lookup_cast_isnull_noop(self):
from django.db.backends.postgresql.operations import DatabaseOperations
do = DatabaseOperations(connection=None)
# Using __isnull lookup doesn't require casting.
tests = [
"CharField",
"EmailField",
"TextField",
]
for field_type in tests:
with self.subTest(field_type=field_type):
self.assertEqual(do.lookup_cast("isnull", field_type), "%s")
def test_correct_extraction_psycopg_version(self):
from django.db.backends.postgresql.base import Database, psycopg_version