diff options
| author | Simon Charette <charette.s@gmail.com> | 2017-04-06 20:28:21 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2017-04-07 16:51:07 -0400 |
| commit | 5d35e8eb0681161f5bc3c0dc2acee68c58786c79 (patch) | |
| tree | 303b3c78d0798959f8147bcb1737b31585e8f5b4 | |
| parent | f9d2a20d7b6cbef24199332d28534e3e16fa20d9 (diff) | |
[1.11.x] Fixed #28038 -- Restored casting to text of builtin lookups on PostgreSQL.
Reverted 658f1e8 which broke code using __icontains's implicit cast to ::text
on ArrayField.
Thanks Peter J. Farrell for the report.
Backport of a354c69055fd818e612ce22eaa2da0576a4b89ee from master
| -rw-r--r-- | django/db/backends/postgresql/operations.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.11.1.txt | 3 | ||||
| -rw-r--r-- | tests/postgres_tests/test_array.py | 8 |
3 files changed, 11 insertions, 2 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index fecea0f826..a66cb0c563 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -83,8 +83,6 @@ class DatabaseOperations(BaseDatabaseOperations): 'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'): if internal_type in ('IPAddressField', 'GenericIPAddressField'): lookup = "HOST(%s)" - elif internal_type in ('CharField', 'TextField'): - lookup = '%s' else: lookup = "%s::text" diff --git a/docs/releases/1.11.1.txt b/docs/releases/1.11.1.txt index 101988819a..d1e054bb18 100644 --- a/docs/releases/1.11.1.txt +++ b/docs/releases/1.11.1.txt @@ -12,3 +12,6 @@ Bugfixes * Made migrations respect ``Index``’s ``name`` argument. If you created a named index with Django 1.11, ``makemigrations`` will create a migration to recreate the index with the correct name (:ticket:`28051`). + +* Fixed a crash when using a ``__icontains`` lookup on a ``ArrayField`` + (:ticket:`28038`). diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 69ae5f3cda..a11b60e261 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -216,6 +216,14 @@ class TestQuerying(PostgreSQLTestCase): self.objs[1:3] ) + def test_icontains(self): + # Using the __icontains lookup with ArrayField is inefficient. + instance = CharArrayModel.objects.create(field=['FoO']) + self.assertSequenceEqual( + CharArrayModel.objects.filter(field__icontains='foo'), + [instance] + ) + def test_contains_charfield(self): # Regression for #22907 self.assertSequenceEqual( |
