diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aebe1b2371..6fad108dab 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -112,6 +112,7 @@ Fixed Contributed by Tatsuma Matsuki (@mtatsuma) * Fix dependency conflicts by updating ``requests`` (2.23.0) and ``gitpython`` (2.1.15). #4869 +* Fixed serializing array parameters (bug fix) #4804, #4861, #4872 3.1.0 - June 27, 2019 --------------------- diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index 39e137c559..a69c16bd3c 100644 --- a/st2common/st2common/util/action_db.py +++ b/st2common/st2common/util/action_db.py @@ -283,9 +283,9 @@ def serialize_positional_argument(argument_type, argument_value): argument_value = '1' if bool(argument_value) else '0' else: argument_value = '' - elif argument_type == 'list': + elif argument_type in ['array', 'list']: # Lists are serialized a comma delimited string (foo,bar,baz) - argument_value = ','.join(argument_value) if argument_value else '' + argument_value = ','.join(map(str, argument_value)) if argument_value else '' elif argument_type == 'object': # Objects are serialized as JSON argument_value = json.dumps(argument_value) if argument_value else '' diff --git a/st2common/tests/unit/test_action_db_utils.py b/st2common/tests/unit/test_action_db_utils.py index 68ee865596..737b9a7c6c 100644 --- a/st2common/tests/unit/test_action_db_utils.py +++ b/st2common/tests/unit/test_action_db_utils.py @@ -327,7 +327,7 @@ def test_get_args(self): 'runnerint': 555 } pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) - self.assertListEqual(pos_args, ['20', '', 'foo', '', '', '', ''], + self.assertListEqual(pos_args, ['20', '', 'foo', '', '', '', '', ''], 'Positional args not parsed correctly.') self.assertNotIn('actionint', named_args) self.assertNotIn('actionstr', named_args) @@ -340,6 +340,7 @@ def test_get_args(self): 'actionfloat': 1.5, 'actionstr': 'string value', 'actionbool': True, + 'actionarray': ['foo', 'bar', 'baz', 'qux'], 'actionlist': ['foo', 'bar', 'baz'], 'actionobject': {'a': 1, 'b': '2'}, } @@ -348,6 +349,7 @@ def test_get_args(self): '1.5', 'string value', '1', + 'foo,bar,baz,qux', 'foo,bar,baz', '{"a": 1, "b": "2"}', '' @@ -361,6 +363,7 @@ def test_get_args(self): 'actionfloat': 1.5, 'actionstr': 'string value', 'actionbool': False, + 'actionarray': [], 'actionlist': [], 'actionobject': {'a': 1, 'b': '2'}, } @@ -370,6 +373,7 @@ def test_get_args(self): 'string value', '0', '', + '', '{"a": 1, "b": "2"}', '' ] @@ -383,6 +387,7 @@ def test_get_args(self): 'actionfloat': None, 'actionstr': None, 'actionbool': None, + 'actionarray': None, 'actionlist': None, 'actionobject': None, } @@ -393,6 +398,7 @@ def test_get_args(self): '', '', '', + '', '' ] pos_args, _ = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) @@ -412,6 +418,7 @@ def test_get_args(self): '', '', '', + '', '' ] pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) @@ -463,9 +470,10 @@ def setup_action_models(cls): 'actionfloat': {'type': 'float', 'required': False, 'position': 1}, 'actionstr': {'type': 'string', 'required': True, 'position': 2}, 'actionbool': {'type': 'boolean', 'required': False, 'position': 3}, - 'actionlist': {'type': 'list', 'required': False, 'position': 4}, - 'actionobject': {'type': 'object', 'required': False, 'position': 5}, - 'actionnull': {'type': 'null', 'required': False, 'position': 6}, + 'actionarray': {'type': 'array', 'required': False, 'position': 4}, + 'actionlist': {'type': 'list', 'required': False, 'position': 5}, + 'actionobject': {'type': 'object', 'required': False, 'position': 6}, + 'actionnull': {'type': 'null', 'required': False, 'position': 7}, 'runnerdummy': {'type': 'string', 'default': 'actiondummy'} }