Merge pull request #22979 from SAY-5/fix-select-dict-value-typeerror

Raise ParameterValueError for unhashable dict select values
This commit is contained in:
Marius van den Beek
2026-07-07 16:40:49 +02:00
committed by GitHub
2 changed files with 19 additions and 0 deletions
+11
View File
@@ -1117,6 +1117,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:
@@ -26,6 +26,14 @@ 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