Skip to content

Commit

Permalink
Fix tool state in build_module and refactor action
Browse files Browse the repository at this point in the history
that can result form upgrading tools.
  • Loading branch information
mvdbeek committed Apr 8, 2024
1 parent b321760 commit 8e8d7fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/galaxy/managers/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/webapps/galaxy/api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions lib/galaxy_test/api/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8e8d7fa

Please sign in to comment.