mirror of
https://github.com/django/django.git
synced 2024-12-27 19:46:22 +00:00
Fixes #24169 -- More arrayfield specific lookups.
varchar()[] cannot compare itself to text[] Thanks to joelburton for the patch.
This commit is contained in:
parent
61c102d010
commit
0ae94d0d31
@ -158,8 +158,20 @@ class ArrayContains(lookups.DataContains):
|
||||
return sql, params
|
||||
|
||||
|
||||
ArrayField.register_lookup(lookups.ContainedBy)
|
||||
ArrayField.register_lookup(lookups.Overlap)
|
||||
@ArrayField.register_lookup
|
||||
class ArrayContainedBy(lookups.ContainedBy):
|
||||
def as_sql(self, qn, connection):
|
||||
sql, params = super(ArrayContainedBy, self).as_sql(qn, connection)
|
||||
sql += '::%s' % self.lhs.output_field.db_type(connection)
|
||||
return sql, params
|
||||
|
||||
|
||||
@ArrayField.register_lookup
|
||||
class ArrayOverlap(lookups.Overlap):
|
||||
def as_sql(self, qn, connection):
|
||||
sql, params = super(ArrayOverlap, self).as_sql(qn, connection)
|
||||
sql += '::%s' % self.lhs.output_field.db_type(connection)
|
||||
return sql, params
|
||||
|
||||
|
||||
@ArrayField.register_lookup
|
||||
|
@ -156,6 +156,18 @@ class TestQuerying(TestCase):
|
||||
[]
|
||||
)
|
||||
|
||||
def test_contained_by_charfield(self):
|
||||
self.assertSequenceEqual(
|
||||
CharArrayModel.objects.filter(field__contained_by=['text']),
|
||||
[]
|
||||
)
|
||||
|
||||
def test_overlap_charfield(self):
|
||||
self.assertSequenceEqual(
|
||||
CharArrayModel.objects.filter(field__overlap=['text']),
|
||||
[]
|
||||
)
|
||||
|
||||
def test_index(self):
|
||||
self.assertSequenceEqual(
|
||||
NullableIntegerArrayModel.objects.filter(field__0=2),
|
||||
|
Loading…
Reference in New Issue
Block a user