fix: handle deleted workflow job in ancestor_job property#16331
fix: handle deleted workflow job in ancestor_job property#16331benthomasson wants to merge 2 commits intoansible:develfrom
Conversation
When a workflow job is deleted while its child jobs still exist, `get_workflow_job()` returns None. The `ancestor_job` property previously called `.ancestor_job` on the None return value, causing an AttributeError 500 in the API (e.g. when serializing summary_fields). Add a null check so that jobs whose parent workflow has been deleted gracefully fall back to treating themselves as the ancestor. Fixes ansible#16250 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughModified the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Covers the crash from ansible#16250 where ancestor_job called .ancestor_job on None when get_workflow_job() returned None for a deleted workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
awx/main/tests/unit/models/test_unified_job_unit.py (1)
40-46: Strengthen this to cover nested workflow ancestry.This only proves a single-hop parent lookup. The reported failure comes from recursive ancestry (
wf1 -> wf2 -> job), so adding a case whereWorkflowJobitself has an ancestor would better protect the intended behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@awx/main/tests/unit/models/test_unified_job_unit.py` around lines 40 - 46, Extend the test_ancestor_job_traverses_workflow to assert recursive ancestry by creating a second WorkflowJob (e.g., wf_parent) that is the ancestor of the first WorkflowJob (wj), then attach wj to wf_parent (so wf_parent -> wj -> child) and verify child.ancestor_job resolves to wf_parent; use the same classes referenced in the diff (WorkflowJob, UnifiedJob, WorkflowJobNode) and the existing mock.patch on django.db.ConnectionRouter.db_for_write to avoid DB access.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@awx/main/tests/unit/models/test_unified_job_unit.py`:
- Around line 40-46: Extend the test_ancestor_job_traverses_workflow to assert
recursive ancestry by creating a second WorkflowJob (e.g., wf_parent) that is
the ancestor of the first WorkflowJob (wj), then attach wj to wf_parent (so
wf_parent -> wj -> child) and verify child.ancestor_job resolves to wf_parent;
use the same classes referenced in the diff (WorkflowJob, UnifiedJob,
WorkflowJobNode) and the existing mock.patch on
django.db.ConnectionRouter.db_for_write to avoid DB access.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e7c9e345-b3f6-4d90-ab40-3a624fa5678d
📒 Files selected for processing (1)
awx/main/tests/unit/models/test_unified_job_unit.py
|



Summary
AttributeError500 error when a workflow job is deleted while its child jobs still existancestor_jobproperty now checks forNonefromget_workflow_job()before recursing, falling back toselfwhen the parent workflow is goneawx/main/models/unified_jobs.pyFixes #16250
Test plan
launched_byandsummary_fieldsserialize correctly when ancestor workflow is deleted🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests