From d040bfb2bb2a6422aa088641a3751b2d78851f76 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 8 Oct 2024 14:58:18 +0200 Subject: [PATCH] assert that data_column parameters have a valid data_ref - it needs to be specified in the XML - needs to refer to an existing parameter --- lib/galaxy/tool_shed/tools/tool_validator.py | 2 +- lib/galaxy/tools/__init__.py | 3 +-- lib/galaxy/tools/parameters/basic.py | 1 + .../missing_data_ref/missing_data_ref.xml | 19 +++++++++++++++++++ .../repos/wrong_data_ref/wrong_data_ref.xml | 19 +++++++++++++++++++ test/unit/tool_shed/test_tool_validation.py | 18 ++++++++++++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 lib/tool_shed/test/test_data/repos/missing_data_ref/missing_data_ref.xml create mode 100644 lib/tool_shed/test/test_data/repos/wrong_data_ref/wrong_data_ref.xml diff --git a/lib/galaxy/tool_shed/tools/tool_validator.py b/lib/galaxy/tool_shed/tools/tool_validator.py index a73af2230c9e..428601c65113 100644 --- a/lib/galaxy/tool_shed/tools/tool_validator.py +++ b/lib/galaxy/tool_shed/tools/tool_validator.py @@ -97,7 +97,7 @@ def load_tool_from_config(self, repository_id, full_path): tool = None valid = False error_message = ( - f'This file requires an entry for "{str(e)}" in the tool_data_table_conf.xml file. Upload a file ' + f'This file requires an entry for "{str(e)}" in the tool_data_table_conf.xml file. Upload a file ' ) error_message += ( "named tool_data_table_conf.xml.sample to the repository that includes the required entry to correct " diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 29800c43b795..0ba93c569ab6 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -1660,8 +1660,7 @@ def parse_param_elem(self, input_source: InputSource, enctypes, context) -> Tool # form when it changes for name in param.get_dependencies(): # Let it throw exception, but give some hint what the problem might be - if name not in context: - log.error(f"Tool with id '{self.id}': Could not find dependency '{name}' of parameter '{param.name}'") + assert name in context, f"Tool with id '{self.id}': Could not find dependency '{name}' of parameter '{param.name}'" context[name].refresh_on_change = True return param diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 1a099bfe7061..7dfe886bd3a3 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1396,6 +1396,7 @@ def __init__(self, tool, input_source): if self.accept_default: self.optional = True self.data_ref = input_source.get("data_ref", None) + assert self.data_ref is not None, f'data_column parameter {self.name} requires a valid data_ref attribute' self.ref_input = None # Legacy style default value specification... self.default_value = input_source.get("default_value", None) diff --git a/lib/tool_shed/test/test_data/repos/missing_data_ref/missing_data_ref.xml b/lib/tool_shed/test/test_data/repos/missing_data_ref/missing_data_ref.xml new file mode 100644 index 000000000000..090972695b10 --- /dev/null +++ b/lib/tool_shed/test/test_data/repos/missing_data_ref/missing_data_ref.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + diff --git a/lib/tool_shed/test/test_data/repos/wrong_data_ref/wrong_data_ref.xml b/lib/tool_shed/test/test_data/repos/wrong_data_ref/wrong_data_ref.xml new file mode 100644 index 000000000000..608dd7aad61c --- /dev/null +++ b/lib/tool_shed/test/test_data/repos/wrong_data_ref/wrong_data_ref.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + diff --git a/test/unit/tool_shed/test_tool_validation.py b/test/unit/tool_shed/test_tool_validation.py index a1f421120ecc..4ca8e82f82ee 100644 --- a/test/unit/tool_shed/test_tool_validation.py +++ b/test/unit/tool_shed/test_tool_validation.py @@ -11,6 +11,8 @@ BOWTIE2_INDICES = os.path.join( galaxy_directory(), "lib/tool_shed/test/test_data/bowtie2_loc_sample/bowtie2_indices.loc.sample" ) +MISSING_DATA_REF_DIR = os.path.join(galaxy_directory(), "lib/tool_shed/test/test_data/repos/missing_data_ref") +WRONG_DATA_REF_DIR = os.path.join(galaxy_directory(), "lib/tool_shed/test/test_data/repos/wrong_data_ref") def test_validate_valid_tool(): @@ -64,6 +66,22 @@ def test_validate_tool_without_index(): assert not tool.params_with_missing_index_file +def test_validate_missing_data_ref(): + repo_dir = MISSING_DATA_REF_DIR + with get_tool_validator() as tv: + full_path = os.path.join(repo_dir, "missing_data_ref.xml") + tool, valid, message = tv.load_tool_from_config(repository_id=None, full_path=full_path) + assert valid is False + + +def test_validate_wrong_data_ref(): + repo_dir = WRONG_DATA_REF_DIR + with get_tool_validator() as tv: + full_path = os.path.join(repo_dir, "wrong_data_ref.xml") + tool, valid, message = tv.load_tool_from_config(repository_id=None, full_path=full_path) + assert valid is True + + @contextmanager def get_tool_validator(): app = MockApp()