← Back to Pull requests

AAP-61789 Fix migration #196

Closed
unknown closed this pull request without merging on Jan 05, 2026 08:29 UTC
View on GitHub
unknown unknown commented on Jan 05, 2026 07:55 UTC
Author

This pull request introduces improvements to the Django migration scripts for the clusters app, focusing on code readability and data consistency. The main changes include refactoring for better formatting, and the addition of a new migration to ensure uniqueness of negative external_id values across several models.

Migration code readability improvements:

Reformatted long lines in the duplicate resolution functions (resolve_duplicates, resolve_label_duplicates, resolve_host_duplicates, and resolve_aap_user_duplicates) to improve readability and maintainability in 0015_auto_20251020_1008.py. [[1]](diffhunk://#diff-e7e29bf7cdc36ba0775692cab6a329a5b0f76ab850deeab4ba4c499ebbedb5eeL4-R5) [[2]](diffhunk://#diff-e7e29bf7cdc36ba0775692cab6a329a5b0f76ab850deeab4ba4c499ebbedb5eeL50-L69) [[3]](diffhunk://#diff-e7e29bf7cdc36ba0775692cab6a329a5b0f76ab850deeab4ba4c499ebbedb5eeL82-R75) [[4]](diffhunk://#diff-e7e29bf7cdc36ba0775692cab6a329a5b0f76ab850deeab4ba4c499ebbedb5eeL98-R88) [[5]](diffhunk://#diff-e7e29bf7cdc36ba0775692cab6a329a5b0f76ab850deeab4ba4c499ebbedb5eeL115-R113)

New migration for unique negative external IDs:

Added a new migration 0016_alter_aapuser_index_together_and_more.py that introduces the unique_negative_external_ids function. This function iterates over several models and ensures that all negative external_id values are unique by reassigning them to new, decremented values. This helps maintain data integrity for objects imported or created with negative IDs.

  • The new migration also includes the use of migrations.RunPython to execute the uniqueness enforcement and alters the index_together constraint for the AAPUser model.
  • Diff: 213 lines (+159 / -54) across 2 files Reviewer: justinc1 Review duration: 33m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.60) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.60 · 213 lines diff across 2 files
    0.60
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.321
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.060
    Real PR Conversation Timeline
    1 comments
    "Review active on #196"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59.7% (MEDIUM) · Higher = larger blast radius
    59.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.6% · Safe to merge
    23.6%