Skip to content

Commit

Permalink
feat: Validate str type before tuple cast
Browse files Browse the repository at this point in the history
  • Loading branch information
ikyasam18 committed Nov 26, 2024
1 parent b1d3ca3 commit 95444a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion luigi/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 95444a3

Please sign in to comment.