From 455a851eef1b9301dc23817604cad73db9016bf0 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 29 May 2024 10:20:45 +0200 Subject: [PATCH] Raise exception when extracting dataset from collection without datasets Fixes https://github.com/galaxyproject/galaxy/issues/18240. --- lib/galaxy/model/__init__.py | 2 +- lib/galaxy/tools/__init__.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 172aab242b03..43d6bbe35586 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -6507,7 +6507,7 @@ def dataset_elements_and_identifiers(self, identifiers=None): return elements @property - def first_dataset_element(self): + def first_dataset_element(self) -> Optional[HistoryDatasetAssociation]: for element in self.elements: if element.is_collection: first_element = element.child_collection.first_dataset_element diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 20d7e4f47608..d1fd2e199bee 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -3355,18 +3355,20 @@ def produce_outputs(self, trans, out_data, output_collections, incoming, history how = incoming["which"]["which_dataset"] if how == "first": extracted_element = collection.first_dataset_element + if not extracted_element: + raise exceptions.RequestParameterInvalidException("Input collection has no dataset elements.") elif how == "by_identifier": try: extracted_element = collection[incoming["which"]["identifier"]] except KeyError as e: - raise exceptions.MessageException(e.args[0]) + raise exceptions.RequestParameterInvalidException(e.args[0]) elif how == "by_index": try: extracted_element = collection[int(incoming["which"]["index"])] except KeyError as e: - raise exceptions.MessageException(e.args[0]) + raise exceptions.RequestParameterInvalidException(e.args[0]) else: - raise exceptions.MessageException("Invalid tool parameters.") + raise exceptions.RequestParameterInvalidException("Invalid tool parameters.") extracted = extracted_element.element_object extracted_o = extracted.copy( copy_tags=extracted.tags, new_name=extracted_element.element_identifier, flush=False