From 101b6b5d23f79caa6279986a6d38627247920d7c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 14 Oct 2024 11:18:36 -0400 Subject: [PATCH] If loading a workflow without a version by instance id - use that instance. --- lib/galaxy/model/__init__.py | 9 +++++++++ lib/galaxy/webapps/galaxy/services/workflows.py | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 4bbc83f787fb..9a06e7703edd 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -7749,6 +7749,15 @@ def get_internal_version(self, version): raise galaxy.exceptions.RequestParameterInvalidException("Version does not exist") return list(reversed(self.workflows))[version] + def get_internal_version_by_id(self, workflow_instance_id: int): + sa_session = object_session(self) + workflow = sa_session.get(Workflow, workflow_instance_id) + if not workflow: + raise galaxy.exceptions.ObjectNotFound() + elif workflow.stored_workflow != self: + raise galaxy.exceptions.RequestParameterInvalidException() + return workflow + def version_of(self, workflow): for version, workflow_instance in enumerate(reversed(self.workflows)): if workflow_instance.id == workflow.id: diff --git a/lib/galaxy/webapps/galaxy/services/workflows.py b/lib/galaxy/webapps/galaxy/services/workflows.py index 72414b169abf..0f7f13b3aa05 100644 --- a/lib/galaxy/webapps/galaxy/services/workflows.py +++ b/lib/galaxy/webapps/galaxy/services/workflows.py @@ -131,7 +131,10 @@ def invoke_workflow( by_stored_id = not payload.instance stored_workflow = self._workflows_manager.get_stored_accessible_workflow(trans, workflow_id, by_stored_id) version = payload.version - workflow = stored_workflow.get_internal_version(version) + if version is None and payload.instance: + workflow = stored_workflow.get_internal_version_by_id(workflow_id) + else: + workflow = stored_workflow.get_internal_version(version) run_configs = build_workflow_run_configs(trans, workflow, payload.model_dump(exclude_unset=True)) is_batch = payload.batch if not is_batch and len(run_configs) != 1: