From 11d4a9165ac4186db5ad3ce04bdf9fe96e9a4fc9 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 20 May 2025 13:46:51 -0500 Subject: [PATCH] [25.0] Rerun workflows for the correct version/instance In `GET /api/workflows/{encoded_workflow_id}/download`, for the case when `instance = True`, we were correctly obtaining the stored workflow. However, then in `WorkflowContentsManager.workflow_to_dict` we were not considering the case that when `instance = True`, we need to not return the `latest_workflow.workflow_to_dict`, and instead return the specific workflow instance which has been specified. We did handle the case when `version` is explicitly provided here, but not instance. Fixes https://github.com/galaxyproject/galaxy/issues/20223 --- lib/galaxy/managers/workflows.py | 8 +++++++- lib/galaxy/webapps/galaxy/api/workflows.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index bea071d0199..c22f22fea0b 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -925,7 +925,7 @@ class WorkflowContentsManager(UsesAnnotations): return workflow, missing_tool_tups - def workflow_to_dict(self, trans, stored, style="export", version=None, history=None): + def workflow_to_dict(self, trans, stored, style="export", version=None, history=None, instance_id=None): """Export the workflow contents to a dictionary ready for JSON-ification and to be sent out via API for instance. There are three styles of export allowed 'export', 'instance', and 'editor'. The Galaxy team will do its best to preserve the backward compatibility of the @@ -942,6 +942,12 @@ class WorkflowContentsManager(UsesAnnotations): version = None if version is not None: version = int(version) + elif instance_id: + # If the instance_id is provided, we need to extract the workflow instance via the version. + for i, workflow in enumerate(reversed(stored.workflows)): + if workflow.id == instance_id: + version = i + break workflow = stored.get_internal_version(version) if style == "export": style = self.app.config.default_workflow_export_format diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index 9a16283230e..636e525e8f0 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -339,13 +339,15 @@ class WorkflowsAPIController( style = kwd.get("style", "export") download_format = kwd.get("format") version = kwd.get("version") + instance = util.string_as_bool(kwd.get("instance", "false")) + instance_id = self.decode_id(workflow_id) if instance else None history = None if history_id := kwd.get("history_id"): history = self.history_manager.get_accessible( self.decode_id(history_id), trans.user, current_history=trans.history ) ret_dict = self.workflow_contents_manager.workflow_to_dict( - trans, stored_workflow, style=style, version=version, history=history + trans, stored_workflow, style=style, version=version, history=history, instance_id=instance_id ) if download_format == "json-download": sname = stored_workflow.name