diff --git a/awx/main/models/workflow.py b/awx/main/models/workflow.py index 60a5f151f2..1f1d776bd4 100644 --- a/awx/main/models/workflow.py +++ b/awx/main/models/workflow.py @@ -527,7 +527,7 @@ class WorkflowJob(UnifiedJob, WorkflowJobOptions, SurveyJobMixin, JobNotificatio 'this is not normal and suggests task manager degeneracy.') break wj_ids.add(wj.pk) - ancestors.append(wj.workflow_job_template_id) + ancestors.append(wj.workflow_job_template) wj = wj.get_workflow_job() return ancestors diff --git a/awx/main/scheduler/task_manager.py b/awx/main/scheduler/task_manager.py index 4936ff74e0..0d7c528566 100644 --- a/awx/main/scheduler/task_manager.py +++ b/awx/main/scheduler/task_manager.py @@ -124,17 +124,18 @@ class TaskManager(): can_start = True if isinstance(spawn_node.unified_job_template, WorkflowJobTemplate): workflow_ancestors = job.get_ancestor_workflows() - if spawn_node.unified_job_template.id in set(workflow_ancestors): + if spawn_node.unified_job_template in set(workflow_ancestors): can_start = False logger.info('Refusing to start recursive workflow-in-workflow id={}, wfjt={}, ancestors={}'.format( - job.id, spawn_node.unified_job_template.id, workflow_ancestors)) + job.id, spawn_node.unified_job_template.pk, [wa.pk for wa in workflow_ancestors])) + display_list = [spawn_node.unified_job_template] + workflow_ancestors job.job_explanation = _( "Workflow Job spawned from workflow could not start because it " - "would result in recursion (template spawn order {})" - ).format([spawn_node.unified_job_template.id] + workflow_ancestors) + "would result in recursion (spawn order, most recent first: {})" + ).format(six.text_type(', ').join([six.text_type('<{}>').format(tmp) for tmp in display_list])) else: logger.debug('Starting workflow-in-workflow id={}, wfjt={}, ancestors={}'.format( - job.id, spawn_node.unified_job_template.id, workflow_ancestors)) + job.id, spawn_node.unified_job_template.pk, [wa.pk for wa in workflow_ancestors])) if not job._resources_sufficient_for_launch(): can_start = False job.job_explanation = _("Job spawned from workflow could not start because it " diff --git a/awx/main/tests/functional/models/test_workflow.py b/awx/main/tests/functional/models/test_workflow.py index 5b57326242..d7d03a53bb 100644 --- a/awx/main/tests/functional/models/test_workflow.py +++ b/awx/main/tests/functional/models/test_workflow.py @@ -249,7 +249,7 @@ def test_workflow_ancestors(organization): job=parent_job ) # ancestors method gives a list of WFJT ids - assert child_job.get_ancestor_workflows() == [parent.pk, grandparent.pk] + assert child_job.get_ancestor_workflows() == [parent, grandparent] @pytest.mark.django_db