Skip to content

Commit

Permalink
Merge pull request #17988 from mvdbeek/fix_subworkflow_upgrade_after_…
Browse files Browse the repository at this point in the history
…rename

[24.0] Use or copy StoredWorkflow when copying step
  • Loading branch information
mvdbeek authored Apr 16, 2024
2 parents 3c2db48 + c7c0baf commit eeca0f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8002,10 +8002,20 @@ def copy_to(self, copied_step, step_mapping, user=None):
copied_step.annotations = annotations

if subworkflow := self.subworkflow:
copied_subworkflow = subworkflow.copy()
copied_step.subworkflow = copied_subworkflow
for subworkflow_step, copied_subworkflow_step in zip(subworkflow.steps, copied_subworkflow.steps):
subworkflow_step_mapping[subworkflow_step.id] = copied_subworkflow_step
stored_subworkflow = subworkflow.stored_workflow
if stored_subworkflow and stored_subworkflow.user == user:
# This should be fine and reduces the number of stored subworkflows
copied_step.subworkflow = subworkflow
else:
# Can this even happen, building a workflow with a subworkflow you don't own ?
copied_subworkflow = subworkflow.copy()
stored_workflow = StoredWorkflow(
user, name=copied_subworkflow.name, workflow=copied_subworkflow, hidden=True
)
copied_subworkflow.stored_workflow = stored_workflow
copied_step.subworkflow = copied_subworkflow
for subworkflow_step, copied_subworkflow_step in zip(subworkflow.steps, copied_subworkflow.steps):
subworkflow_step_mapping[subworkflow_step.id] = copied_subworkflow_step

for old_conn, new_conn in zip(self.input_connections, copied_step.input_connections):
new_conn.input_step_input = copied_step.get_or_add_input(old_conn.input_name)
Expand Down
3 changes: 3 additions & 0 deletions test/unit/data/test_galaxy_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ def test_workflows(self):
assert loaded_invocation
assert loaded_invocation.history.id == history_id

# recover user after expunge
user = loaded_invocation.history.user

step_1, step_2 = loaded_invocation.workflow.steps

assert not step_1.subworkflow
Expand Down

0 comments on commit eeca0f1

Please sign in to comment.