From 404b47657688dc472ef22c9c83240a2bb9206054 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Wed, 25 Apr 2018 11:46:21 -0400 Subject: [PATCH] Allow real null to be searched in host_filter --- awx/main/tests/unit/utils/test_filters.py | 8 ++++++-- awx/main/utils/filters.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/awx/main/tests/unit/utils/test_filters.py b/awx/main/tests/unit/utils/test_filters.py index 964466cb73..c0b38d294c 100644 --- a/awx/main/tests/unit/utils/test_filters.py +++ b/awx/main/tests/unit/utils/test_filters.py @@ -39,6 +39,7 @@ class TestSmartFilterQueryFromString(): ('a__b__c=3.14', Q(**{u"a__b__c": 3.14})), ('a__b__c=true', Q(**{u"a__b__c": True})), ('a__b__c=false', Q(**{u"a__b__c": False})), + ('a__b__c=null', Q(**{u"a__b__c": None})), ('ansible_facts__a="true"', Q(**{u"ansible_facts__contains": {u"a": u"true"}})), #('"a__b\"__c"="true"', Q(**{u"a__b\"__c": "true"})), #('a__b\"__c="true"', Q(**{u"a__b\"__c": "true"})), @@ -114,7 +115,7 @@ class TestSmartFilterQueryFromString(): assert six.text_type(q) == six.text_type(q_expected) @pytest.mark.parametrize("filter_string,q_expected", [ - ('ansible_facts__a=null', Q(**{u"ansible_facts__contains": {u"a": u"null"}})), + ('ansible_facts__a=null', Q(**{u"ansible_facts__contains": {u"a": None}})), ('ansible_facts__c="null"', Q(**{u"ansible_facts__contains": {u"c": u"\"null\""}})), ]) def test_contains_query_generated_null(self, mock_get_host_model, filter_string, q_expected): @@ -130,7 +131,10 @@ class TestSmartFilterQueryFromString(): Q(**{u"group__name__contains": u"foo"}) | Q(**{u"group__description__contains": u"foo"}))), ('search=foo or ansible_facts__a=null', Q(Q(**{u"name__contains": u"foo"}) | Q(**{u"description__contains": u"foo"})) | - Q(**{u"ansible_facts__contains": {u"a": u"null"}})), + Q(**{u"ansible_facts__contains": {u"a": None}})), + ('search=foo or ansible_facts__a="null"', + Q(Q(**{u"name__contains": u"foo"}) | Q(**{u"description__contains": u"foo"})) | + Q(**{u"ansible_facts__contains": {u"a": u"\"null\""}})), ]) def test_search_related_fields(self, mock_get_host_model, filter_string, q_expected): q = SmartFilter.query_from_string(filter_string) diff --git a/awx/main/utils/filters.py b/awx/main/utils/filters.py index a1d316ba72..81f91a0b0a 100644 --- a/awx/main/utils/filters.py +++ b/awx/main/utils/filters.py @@ -19,6 +19,8 @@ __all__ = ['SmartFilter'] def string_to_type(t): + if t == u'null': + return None if t == u'true': return True elif t == u'false':