diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-07-15 12:13:23 +0100 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-07-15 19:41:26 +0100 |
| commit | b65a2001e7be3811903fc8769fa4d3df3d324f18 (patch) | |
| tree | 26aa4036c06e8803f674840825fc7d7ab837cccf | |
| parent | 9a2ab629776735fae2c9184dc4b9d9029bad15b2 (diff) | |
Fixed #22907 -- Array contains must have same type.
| -rw-r--r-- | django/contrib/postgres/fields/array.py | 3 | ||||
| -rw-r--r-- | tests/postgres_tests/test_array.py | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index a33af7be64..772ab9e586 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -159,7 +159,8 @@ class ArrayContainsLookup(Lookup): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) params = lhs_params + rhs_params - return '%s @> %s' % (lhs, rhs), params + type_cast = self.lhs.source.db_type(connection) + return '%s @> %s::%s' % (lhs, rhs, type_cast), params ArrayField.register_lookup(ArrayContainsLookup) diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index b8ae48c5bc..1fc54defe7 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -118,6 +118,13 @@ class TestQuerying(TestCase): self.objs[1:3] ) + def test_contains_charfield(self): + # Regression for #22907 + self.assertSequenceEqual( + CharArrayModel.objects.filter(field__contains=['text']), + [] + ) + def test_index(self): self.assertSequenceEqual( NullableIntegerArrayModel.objects.filter(field__0=2), |
