Raise ParameterValueError for unhashable dict select values

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
This commit is contained in:
Sai Asish Y
2026-06-19 17:46:32 -07:00
parent f91f8f21ed
commit 7d489ee5ea
2 changed files with 21 additions and 0 deletions
+11
View File
@@ -1116,6 +1116,17 @@ class SelectToolParameter(ToolParameter):
)
if is_runtime_value(value):
return None
if isinstance(value, dict):
# A dict is unhashable and can never be a legal value, but
# testing membership against the set of legal values would
# raise an opaque "unhashable type" TypeError. Treat it as an
# invalid option instead.
raise ParameterValueError(
f"an invalid option ({value!r}) was selected (valid options: {','.join(iter_to_string(legal_values))})",
self.name,
value,
is_dynamic=self.is_dynamic,
)
if value in legal_values:
return value
elif value in fallback_values:
@@ -27,6 +27,16 @@ class TestSelectToolParameter(BaseParameterTestCase):
self.param.from_json("42", self.trans)
assert str(exc_info.value) == "Parameter 'my_name': requires a value, but no legal values defined"
def test_dict_value_is_invalid_option(self):
# A dict value is unhashable; checking it against the set of legal
# values used to raise an opaque "unhashable type: 'dict'" TypeError.
param = self._parameter_for(
xml="""<param name="my_name" type="select"><option value="a">A</option></param>"""
)
with pytest.raises(ValueError) as exc_info:
param.from_json({"not": "valid"}, self.trans)
assert "an invalid option" in str(exc_info.value)
def test_unvalidated_values(self):
self.options_xml = """<options><filter type="data_meta" ref="input_bam" key="dbkey"/></options>"""
self.trans.workflow_building_mode = True