Skip to content

Commit

Permalink
Merge pull request #18249 from mvdbeek/fix_no_elements_exception_extr…
Browse files Browse the repository at this point in the history
…act_dataset

[24.0] Raise exception when extracting dataset from collection without datasets
  • Loading branch information
jmchilton authored May 30, 2024
2 parents 1dd31f0 + 455a851 commit 4c8b4bf
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 4c8b4bf

Please sign in to comment.