Browse files

Fixed #22907 -- Array contains must have same type.

  • Loading branch information...
1 parent 9a2ab62 commit b65a2001e7be3811903fc8769fa4d3df3d324f18 @mjtamlyn mjtamlyn committed Jul 15, 2014
Showing with 9 additions and 1 deletion.
  1. +2 −1 django/contrib/postgres/fields/array.py
  2. +7 −0 tests/postgres_tests/test_array.py
View
3 django/contrib/postgres/fields/array.py
@@ -159,7 +159,8 @@ def as_sql(self, qn, connection):
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)
View
7 tests/postgres_tests/test_array.py
@@ -118,6 +118,13 @@ def test_contains(self):
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),

0 comments on commit b65a200

Please sign in to comment.