[AAP-81383] - Handle renamed job templates and organizations during sync #249
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 163 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.305
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #249"
general
weight: 0.35
justinc1
When AAP deletes and recreates a resource with the same name but a new external ID, the sync would attempt to create a duplicate DB row rather than updating the existing one. This violated the unique constraint on (cluster, name, organization) and caused the sync task to fail.
Switch from create() to update_or_create() keyed on (cluster, name, organization) so that a changed external ID updates the existing row in place. For job templates, also purge the stale external_id key from the in-memory cleanup map to prevent the just-updated row from being incorrectly deleted at the end of the sync.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Bug Fixes
Improved sync behavior so existing job templates and organizations are updated in place when they reappear with the same name but a new identifier.
Prevented accidental removal or duplication during reconciliation by matching records more reliably.
Ensured related fields like description and external ID stay consistent without breaking the existing cleanup of missing templates.
Tests
Added unit tests covering stale external IDs for job templates and duplicate handling for organizations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->