From ce0b448d59b04f6161f59c9edfdfc16c8a998f06 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Tue, 11 Feb 2020 19:53:22 +0100 Subject: [PATCH 1/7] - match for argument_type 'array' instead of 'list' to be compliant with the documentation - handle the parameter and transform the array to a string of comma-separated values --- st2common/st2common/util/action_db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index 39e137c559..772af603df 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 == 'array': # 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 '' From 6d62e023cc93977e31db5b2a4f7a988e01b0df1d Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Tue, 11 Feb 2020 22:31:56 +0100 Subject: [PATCH 2/7] check the parameter type for 'array' and 'list' and not just array --- st2common/st2common/util/action_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index 772af603df..515833b5c3 100644 --- a/st2common/st2common/util/action_db.py +++ b/st2common/st2common/util/action_db.py @@ -283,7 +283,7 @@ def serialize_positional_argument(argument_type, argument_value): argument_value = '1' if bool(argument_value) else '0' else: argument_value = '' - elif argument_type == 'array': + elif argument_type in [ 'array', 'list' ]: # Lists are serialized a comma delimited string (foo,bar,baz) argument_value = ','.join(map(str, argument_value)) if argument_value else '' elif argument_type == 'object': From f262b1af6b8a411a6b0c4b050b44c30674427d3c Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Thu, 13 Feb 2020 10:25:52 +0100 Subject: [PATCH 3/7] remove spaces between the square brackets and array values to pass lint checks --- st2common/st2common/util/action_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index 515833b5c3..a69c16bd3c 100644 --- a/st2common/st2common/util/action_db.py +++ b/st2common/st2common/util/action_db.py @@ -283,7 +283,7 @@ def serialize_positional_argument(argument_type, argument_value): argument_value = '1' if bool(argument_value) else '0' else: argument_value = '' - elif argument_type in [ 'array', 'list' ]: + elif argument_type in ['array', 'list']: # Lists are serialized a comma delimited string (foo,bar,baz) argument_value = ','.join(map(str, argument_value)) if argument_value else '' elif argument_type == 'object': From 25558aa6ae1d963c2e07ebe7ab8822796fb7054f Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Thu, 13 Feb 2020 20:14:37 +0100 Subject: [PATCH 4/7] add unit tests for action parameter type array --- st2common/tests/unit/test_action_db_utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/st2common/tests/unit/test_action_db_utils.py b/st2common/tests/unit/test_action_db_utils.py index c092a3ffda..f728695821 100644 --- a/st2common/tests/unit/test_action_db_utils.py +++ b/st2common/tests/unit/test_action_db_utils.py @@ -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) @@ -463,9 +469,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'} } From 18a88283c19bf0ee141dde3f27ae8d4725f77d7b Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Fri, 14 Feb 2020 11:27:56 +0100 Subject: [PATCH 5/7] fix failing assert on unit tests --- st2common/tests/unit/test_action_db_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/st2common/tests/unit/test_action_db_utils.py b/st2common/tests/unit/test_action_db_utils.py index f728695821..c739c92d2d 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.assertTrue('actionint' not in named_args) self.assertTrue('actionstr' not in named_args) @@ -398,7 +398,6 @@ def test_get_args(self): '', '', '', - '', '' ] pos_args, _ = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) From d74a2e1ff7d4a40fd49612ea0e7f3811e15c327b Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Fri, 14 Feb 2020 11:31:33 +0100 Subject: [PATCH 6/7] fix last unit test --- st2common/tests/unit/test_action_db_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/st2common/tests/unit/test_action_db_utils.py b/st2common/tests/unit/test_action_db_utils.py index c739c92d2d..b2a5b6b56c 100644 --- a/st2common/tests/unit/test_action_db_utils.py +++ b/st2common/tests/unit/test_action_db_utils.py @@ -398,6 +398,7 @@ def test_get_args(self): '', '', '', + '', '' ] pos_args, _ = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) @@ -417,6 +418,7 @@ def test_get_args(self): '', '', '', + '', '' ] pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) From 6d80db953b3b2db63d37bfef133eb4ee318e1dce Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 21 Feb 2020 16:12:00 -0800 Subject: [PATCH 7/7] Add changelog entry --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b861fb58b0..cfd5e53193 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -110,6 +110,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 ---------------------