Skip to content

Commit

Permalink
Raise exception when extracting dataset from collection without datasets
Browse files Browse the repository at this point in the history
Fixes #18240.
  • Loading branch information
mvdbeek committed May 29, 2024
1 parent 316eb5b commit 455a851
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 455a851

Please sign in to comment.