Refs #31829 -- Added DatabaseFeatures.json_key_contains_list_matching_requires_list.
CockroachDB's behavior matches PostgreSQL.
This commit is contained in:
parent
eb215da363
commit
184a6eebb0
|
@ -298,6 +298,9 @@ class BaseDatabaseFeatures:
|
||||||
# Does the backend support __contains and __contained_by lookups for
|
# Does the backend support __contains and __contained_by lookups for
|
||||||
# a JSONField?
|
# a JSONField?
|
||||||
supports_json_field_contains = True
|
supports_json_field_contains = True
|
||||||
|
# Does value__d__contains={'f': 'g'} (without a list around the dict) match
|
||||||
|
# {'d': [{'f': 'g'}]}?
|
||||||
|
json_key_contains_list_matching_requires_list = False
|
||||||
|
|
||||||
def __init__(self, connection):
|
def __init__(self, connection):
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
|
|
|
@ -57,6 +57,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
validates_explain_options = False # A query will error on invalid options.
|
validates_explain_options = False # A query will error on invalid options.
|
||||||
supports_deferrable_unique_constraints = True
|
supports_deferrable_unique_constraints = True
|
||||||
has_json_operators = True
|
has_json_operators = True
|
||||||
|
json_key_contains_list_matching_requires_list = True
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def introspected_field_types(self):
|
def introspected_field_types(self):
|
||||||
|
|
|
@ -714,8 +714,9 @@ class TestQuerying(TestCase):
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
# PostgreSQL requires a layer of nesting.
|
# For databases where {'f': 'g'} (without surrounding []) matches
|
||||||
if connection.vendor != 'postgresql':
|
# [{'f': 'g'}].
|
||||||
|
if not connection.features.json_key_contains_list_matching_requires_list:
|
||||||
tests.append(('value__d__contains', {'f': 'g'}))
|
tests.append(('value__d__contains', {'f': 'g'}))
|
||||||
for lookup, value in tests:
|
for lookup, value in tests:
|
||||||
with self.subTest(lookup=lookup, value=value):
|
with self.subTest(lookup=lookup, value=value):
|
||||||
|
|
Loading…
Reference in New Issue