diff --git a/flytekit/common/types/containers.py b/flytekit/common/types/containers.py index 6ed1962152..211ac7fa08 100644 --- a/flytekit/common/types/containers.py +++ b/flytekit/common/types/containers.py @@ -55,16 +55,15 @@ def from_string(cls, string_value): :param Text string_value: :rtype: ListImpl """ - try: items = _json.loads(string_value) except ValueError: raise _user_exceptions.FlyteTypeException( - _six.text_type, TypedListImpl, additional_msg='String not parseable to json {}'.format(string_value)) + _six.text_type, cls, additional_msg='String not parseable to json {}'.format(string_value)) if type(items) != list: raise _user_exceptions.FlyteTypeException( - _six.text_type, TypedListImpl, additional_msg='String is not a list {}'.format(string_value)) + _six.text_type, cls, additional_msg='String is not a list {}'.format(string_value)) # Instead of recursively calling from_string(), we're changing to from_python_std() instead because json # loading naturally interprets all layers, not just the outer layer. @@ -130,7 +129,7 @@ def to_python_std(self): """ :rtype: list[T] """ - return [self._sub_type.from_flyte_idl(l.to_flyte_idl()).to_python_std() for l in self.collection.literals] + return [type(self).sub_type.from_flyte_idl(l.to_flyte_idl()).to_python_std() for l in self.collection.literals] def short_string(self): """ diff --git a/setup.cfg b/setup.cfg index cf8fb420d7..322b49873c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ max-complexity=16 [tool:pytest] norecursedirs = common workflows spark log_cli = true -log_cli_level = 0 +log_cli_level = 100 [pep8] max-line-length = 120 diff --git a/tests/flytekit/unit/common_tests/types/test_containers.py b/tests/flytekit/unit/common_tests/types/test_containers.py index d5721d4ef6..d44ce06274 100644 --- a/tests/flytekit/unit/common_tests/types/test_containers.py +++ b/tests/flytekit/unit/common_tests/types/test_containers.py @@ -45,6 +45,12 @@ def test_list(): with pytest.raises(_user_exceptions.FlyteTypeException): list_type.from_string('[1, 2, 3, []]') + with pytest.raises(_user_exceptions.FlyteTypeException): + list_type.from_string('\'["not list json"]\'') + + with pytest.raises(_user_exceptions.FlyteTypeException): + list_type.from_string('["unclosed","list"') + def test_string_list(): list_type = containers.List(primitives.String)