Skip to content

Commit

Permalink
Refactor tool expansion checks for reuse in tool request branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 30, 2024
1 parent 208b818 commit e1af290
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,18 +1827,7 @@ def expand_incoming(
collection_info: Optional[MatchingCollections]
expanded_incomings, collection_info = expand_meta_parameters(request_context, self, incoming)

# Remapping a single job to many jobs doesn't make sense, so disable
# remap if multi-runs of tools are being used.
produces_multiple_jobs = len(expanded_incomings) > 1
if rerun_remap_job_id and produces_multiple_jobs:
raise exceptions.RequestParameterInvalidException(
f"Failure executing tool with id '{self.id}' (cannot create multiple jobs when remapping existing job)."
)

if self.input_translator and produces_multiple_jobs:
raise exceptions.RequestParameterInvalidException(
f"Failure executing tool with id '{self.id}' (cannot create multiple jobs with this type of data source tool)."
)
self._ensure_expansion_is_valid(expanded_incomings, rerun_remap_job_id)

# Process incoming data
validation_timer = self.app.execution_timer_factory.get_timer(
Expand All @@ -1857,6 +1846,25 @@ def expand_incoming(
log.info(validation_timer)
return all_params, all_errors, rerun_remap_job_id, collection_info

def _ensure_expansion_is_valid(
self, expanded_incomings: List[ToolStateJobInstanceT], rerun_remap_job_id: Optional[int]
) -> None:
"""If the request corresponds to multiple jobs but this doesn't work with request configuration - raise an error.
In particular check if this is a data source job or if we're remapping a single job - in either case we should
not have any expansion occuring.
"""
produces_multiple_jobs = len(expanded_incomings) > 1
if rerun_remap_job_id and produces_multiple_jobs:
raise exceptions.RequestParameterInvalidException(
f"Failure executing tool with id '{self.id}' (cannot create multiple jobs when remapping existing job)."
)

if self.input_translator and produces_multiple_jobs:
raise exceptions.RequestParameterInvalidException(
f"Failure executing tool with id '{self.id}' (cannot create multiple jobs with this type of data source tool)."
)

def _populate(
self, request_context, expanded_incoming: ToolStateJobInstanceT, input_format: InputFormatT
) -> Tuple[ToolStateJobInstancePopulatedT, ParameterValidationErrorsT]:
Expand Down

0 comments on commit e1af290

Please sign in to comment.