Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe attach method now uses ChangesRelationship membership
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change preserves relationship scoping while replacing full materialization with bounded membership queries; no merge-blocking risk is evidenced. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
❌ Test Results - FAILEDSummary
Pass Rate: 91.3% ❌ Failed Tests
|
❌ Test Results - FAILEDSummary
Pass Rate: 91.5% ❌ Failed Tests
|
|



SUMMARY
Fixes a hang/timeout on
POST /api/v2/inventories/{id}/hosts/for inventories with thousands of hosts.SubListCreateAttachDetachAPIView.attach()'s membership check usedif sub not in relationship.all(). Django's QuerySet has no__contains__, so it falls back to iterating the entire related queryset for a nested host create, that means fetching and JSON-decoding every host in the inventory (including each one's variables field) just to confirm one host is already attached. Cost scales with total host count, not with the request itself.Swapped it for Django's built-in
QuerySet.contains()(available since Django 5.0, we're on 5.2.8), which compiles to a single indexed, LIMIT 1-bounded existence check for the specific host'spkinstead of materializing the whole collection. Same semantics, no behavior change for callers, this is also the shared pattern behind every otherSubListCreateAttachDetachAPIView/SubListAttachDetachAPIViewsubclass (HostGroupsList,RoleUsersList,RoleTeamsList,InventoryInstanceGroupsList, etc.), so the fix benefits all of them, not just inventory hosts.ISSUE TYPE
COMPONENT NAME
STEPS TO REPRODUCE AND EXTRA INFO
Verified against a real 6,251-host inventory on a running instance:
Added a regression test asserting the membership-check SQL is id-filtered and LIMIT-bounded, a plain query-count assertion doesn't catch this, since both the broken and fixed code issue exactly one query; the defect is in that query's cost, not its count.
Summary by CodeRabbit
Performance
Bug Fixes