From 8e8d7fa0f9b5e84da9b3020d09d5563ddf16f1e4 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 8 Apr 2024 20:04:33 +0200 Subject: [PATCH] Fix tool state in build_module and refactor action that can result form upgrading tools. --- lib/galaxy/managers/workflows.py | 4 ++- lib/galaxy/webapps/galaxy/api/workflows.py | 3 ++- lib/galaxy_test/api/test_workflows.py | 30 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index fd955910be3d..79cadc38f36b 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -1461,6 +1461,8 @@ def _workflow_to_dict_export(self, trans, stored=None, workflow=None, internal=F if not annotation_str and annotation_owner: annotation_str = self.get_item_annotation_str(trans.sa_session, annotation_owner, step) or "" content_id = module.get_content_id() if allow_upgrade else step.content_id + # Fix state if necessary + errors = module.check_and_update_state() # Export differences for backward compatibility tool_state = module.get_export_state() # Step info @@ -1472,7 +1474,7 @@ def _workflow_to_dict_export(self, trans, stored=None, workflow=None, internal=F "tool_version": module.get_version() if allow_upgrade else step.tool_version, "name": module.get_name(), "tool_state": json.dumps(tool_state), - "errors": module.get_errors(), + "errors": errors, "uuid": str(step.uuid), "label": step.label or None, "annotation": annotation_str, diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index 853cad1ccc96..54386e7596c6 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -541,9 +541,10 @@ def build_module(self, trans: GalaxyWebTransaction, payload=None): module = module_factory.from_dict(trans, payload, from_tool_form=True) if "tool_state" not in payload: module_state: Dict[str, Any] = {} - errors = {} + errors: Dict[str, str] = {} populate_state(trans, module.get_inputs(), inputs, module_state, errors=errors, check=True) module.recover_state(module_state, from_tool_form=True) + module.check_and_update_state() step_dict = { "name": module.get_name(), "tool_state": module_state, diff --git a/lib/galaxy_test/api/test_workflows.py b/lib/galaxy_test/api/test_workflows.py index a5b884ec3b8a..8ff66bf90e5e 100644 --- a/lib/galaxy_test/api/test_workflows.py +++ b/lib/galaxy_test/api/test_workflows.py @@ -970,6 +970,36 @@ def test_refactor(self): workflow_dict = self.workflow_populator.download_workflow(workflow_id) assert workflow_dict["steps"]["0"]["label"] == "new_label" + def test_refactor_tool_state_upgrade(self): + workflow_id = self.workflow_populator.upload_yaml_workflow( + """ +class: GalaxyWorkflow +inputs: {} +steps: + multiple_versions_changes: + tool_id: multiple_versions_changes + tool_version: "0.1" + state: + inttest: 1 + cond: + bool_to_select: false +""" + ) + actions = [{"action_type": "upgrade_all_steps"}] + refactor_response = self.workflow_populator.refactor_workflow(workflow_id, actions, dry_run=True) + refactor_response.raise_for_status() + refactor_result = refactor_response.json() + upgrade_result = refactor_result["action_executions"][0] + assert upgrade_result["action"]["action_type"] == "upgrade_all_steps" + message_one, message_two = upgrade_result["messages"] + assert message_one["message"] == "No value found for 'floattest'. Using default: '1.0'." + assert message_one["input_name"] == "floattest" + assert message_two["message"] == "The selected case is unavailable/invalid. Using default: 'b'." + assert message_two["input_name"] == "cond|bool_to_select" + + refactor_response = self.workflow_populator.refactor_workflow(workflow_id, actions, dry_run=False) + refactor_response.raise_for_status() + def test_update_no_tool_id(self): workflow_object = self.workflow_populator.load_workflow(name="test_import") upload_response = self.__test_upload(workflow=workflow_object)