diff --git a/core/executionelements/workflow.py b/core/executionelements/workflow.py index c3d3581b3..a1ee513ea 100644 --- a/core/executionelements/workflow.py +++ b/core/executionelements/workflow.py @@ -271,6 +271,19 @@ def get_execution_uid(self): """ return self._execution_uid + def regenerate_uids(self): + start_step = deepcopy(self.steps.pop(self.start, None)) + if start_step is not None: + start_step = deepcopy(start_step) + super(Workflow, self).regenerate_uids() + self.steps = {step.uid: step for step in self.steps.values()} + start_step.regenerate_uids() + self.start = start_step.uid + self.steps[self.start] = start_step + else: + super(Workflow, self).regenerate_uids() + + def strip_async_result(self, with_deepcopy=False): """Removes the AsyncResult object from all of the Steps, necessary to deepcopy a Workflow diff --git a/core/playbookstore.py b/core/playbookstore.py index 12a226c95..8fc1c782f 100644 --- a/core/playbookstore.py +++ b/core/playbookstore.py @@ -293,8 +293,8 @@ def copy_workflow(self, old_playbook_name, new_playbook_name, old_workflow_name, workflow_copy = deepcopy(workflow) workflow_copy.name = new_workflow_name - workflow_copy.reset_async_result() workflow_copy.regenerate_uids() + workflow_copy.reset_async_result() workflow.reload_async_result(steps) @@ -317,8 +317,6 @@ def copy_playbook(self, old_playbook_name, new_playbook_name): for workflow in self.playbooks[old_playbook_name].workflows.values(): self.copy_workflow(old_playbook_name, new_playbook_name, workflow.name, workflow.name) - self.playbooks[new_playbook_name].regenerate_uids() - def get_workflows_by_uid(self, workflow_uids): """Gets a list of workflows from their UIDs diff --git a/tests/test_workflow_server.py b/tests/test_workflow_server.py index 0228ba21a..1763a41ee 100644 --- a/tests/test_workflow_server.py +++ b/tests/test_workflow_server.py @@ -462,13 +462,13 @@ def test_copy_workflow(self): original_workflow_json = workflow_original.read() copy_workflow_json.pop('name', None) original_workflow_json.pop('name', None) + self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start']) + copy_workflow_json.pop('start', None) + original_workflow_json.pop('start', None) TestWorkflowServer.strip_uids(copy_workflow_json) TestWorkflowServer.strip_uids(original_workflow_json) self.assertDictEqual(copy_workflow_json, original_workflow_json) self.assertEqual(len(workflow_original.steps), len(workflow_copy.steps)) - for step in workflow_copy.steps: - self.assertEqual(len(workflow_original.steps[step].next_steps), - len(workflow_copy.steps[step].next_steps)) def test_copy_workflow_invalid_name(self): data = {"workflow": "helloWorldWorkflow"} @@ -505,15 +505,15 @@ def test_copy_workflow_different_playbook(self): original_workflow_json = workflow_original.read() copy_workflow_json.pop('name', None) original_workflow_json.pop('name', None) + self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start']) + copy_workflow_json.pop('start', None) + original_workflow_json.pop('start', None) TestWorkflowServer.strip_uids(copy_workflow_json) TestWorkflowServer.strip_uids(original_workflow_json) self.assertDictEqual(copy_workflow_json, original_workflow_json) self.assertEqual(len(workflow_original.steps), len(workflow_copy.steps)) - for step in workflow_copy.steps: - self.assertEqual(len(workflow_original.steps[step].next_steps), - len(workflow_copy.steps[step].next_steps)) def test_copy_playbook(self): self.post_with_status_check('/api/playbooks/test/copy',