From 95444a3486f6716f468f8b26b0ce1eaa04942cd7 Mon Sep 17 00:00:00 2001 From: ikyasam18 Date: Tue, 26 Nov 2024 16:51:45 +0900 Subject: [PATCH] feat: Validate str type before tuple cast --- luigi/parameter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/luigi/parameter.py b/luigi/parameter.py index 41cc6bc32f..51f6f83802 100644 --- a/luigi/parameter.py +++ b/luigi/parameter.py @@ -1384,7 +1384,12 @@ def parse(self, x): # loop required to parse tuple of tuples return tuple(self._convert_iterable_to_tuple(x) for x in json.loads(x, object_pairs_hook=FrozenOrderedDict)) except (ValueError, TypeError): - return tuple(literal_eval(x)) # if this causes an error, let that error be raised. + result = literal_eval(x) + # t_str = '("abcd")' + # Ensure that the result is not a string to avoid cases like ('a','b','c','d') + if isinstance(result, str): + raise ValueError("Parsed result cannot be a string") + return tuple(result) # if this causes an error, let that error be raised. def _convert_iterable_to_tuple(self, x): if isinstance(x, str):