mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #22979 from SAY-5/fix-select-dict-value-typeerror
Raise ParameterValueError for unhashable dict select values
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user