1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

add json a=null support and still support a="null"

related to #6016
This commit is contained in:
Chris Meyers 2017-04-13 16:26:35 -04:00
parent f20bf127b4
commit 5ff4966526
2 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,11 @@ class JSONField(upstream_JSONField):
class JSONBField(upstream_JSONBField): class JSONBField(upstream_JSONBField):
def get_prep_lookup(self, lookup_type, value):
if isinstance(value, basestring) and value == "null":
return 'null'
return super(JSONBField, self).get_prep_lookup(lookup_type, value)
def get_db_prep_value(self, value, connection, prepared=False): def get_db_prep_value(self, value, connection, prepared=False):
if connection.vendor == 'sqlite': if connection.vendor == 'sqlite':
# sqlite (which we use for tests) does not support jsonb; # sqlite (which we use for tests) does not support jsonb;
@ -405,7 +410,7 @@ class DynamicFilterField(models.TextField):
Note: we could have totally "ripped" them off earlier when we decided Note: we could have totally "ripped" them off earlier when we decided
what type to convert the token to. what type to convert the token to.
''' '''
if type(v) is unicode and v.startswith('"') and v.endswith('"'): if type(v) is unicode and v.startswith('"') and v.endswith('"') and v != u'"null"':
v = v[1:-1] v = v[1:-1]
if contains_count == 0: if contains_count == 0:

View File

@ -86,6 +86,14 @@ class TestDynamicFilterFieldFilterStringToQ():
q = DynamicFilterField.filter_string_to_q(filter_string) q = DynamicFilterField.filter_string_to_q(filter_string)
assert unicode(q) == unicode(q_expected) assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string,q_expected", [
('a__b__c=null', Q(**{u"a__b__c": u"null"})),
('a__b__c="null"', Q(**{u"a__b__c": u"\"null\""})),
])
def test_contains_query_generated_null(self, filter_string, q_expected):
q = DynamicFilterField.filter_string_to_q(filter_string)
assert unicode(q) == unicode(q_expected)
''' '''
#('"facts__quoted_val"="f\"oo"', 1), #('"facts__quoted_val"="f\"oo"', 1),