Fix: scope input_inventories name lookup to organization (awx.awx.inventory) - #16630
maroofsangi wants to merge 9 commits into
Conversation
… filter Adds an optional `data` kwarg to `resolve_name_to_id()` so callers can scope name lookups (e.g. by organization) the same way `get_one()` already supports. Fully backward compatible — every existing caller passes only (endpoint, name_or_id). Fixes ansible#16393 Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
The input_inventories loop called resolve_name_to_id('inventories', item)
without any organization scope, so a name that exists in more than one
organization made the lookup ambiguous and the module failed with
"Request to /api/v2/inventories/?name=X returned 2 items, expected 1",
even though the constructed inventory itself was correctly scoped by org.
Fixes ansible#16393
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Covers ansible#16393: a constructed inventory referencing an input inventory by name that also exists in a different organization should resolve to the input inventory in its own organization, not fail with an ambiguous-match error. Signed-off-by: Maroof Ahmed <93856882+maroofsangi@users.noreply.github.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change adds optional query data to ChangesConstructed inventory input scoping
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Organization-scoped name resolution prevents ambiguous inventory references without introducing a merge-blocking risk; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Documents the new optional `data` parameter and existing behavior. Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
Signed-off-by: Maroof Ahmed <93856682+maroofsangi@users.noreply.github.com>
SUMMARY
Fixes #16393 — the
awx.awx.inventorymodule fails when a constructed inventory'sinput_inventoriesreferences an inventory name that also exists in another organization.Root cause
resolve_name_to_id()incontroller_api.pycallsget_exactly_one()with no scoping data, so a name search across the whole/api/v2/inventories/endpoint (not scoped to any organization) can return more than one match:This happens even though the constructed inventory itself is correctly scoped by organization elsewhere in the same module (
module.get_one('inventories', name_or_id=name, **{'data': {'organization': org_id}})).Fix
controller_api.py—resolve_name_to_id()now accepts an optionaldatakwarg and forwards it toget_exactly_one()/get_one(), the same wayget_one()already supports scoped lookups elsewhere in this file. This is fully backward compatible: every other call site in the collection (26 of them, checked) callsresolve_name_to_id(endpoint, name_or_id)with nodatakwarg, so this is a pure additive change.inventory.py— theinput_inventoriesresolution loop now passesdata={'organization': org_id}so the lookup is scoped to the same organization as the constructed inventory, matching the pattern already used for the inventory name lookup a few lines above.test_constructed_inventory_input_inventories_scoped_to_organization) that creates two organizations each with an inventory of the same name, and verifies a constructed inventory in one organization resolvesinput_inventoriesto its own organization's inventory rather than failing on an ambiguous match.ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Before this fix, per the original issue, the only workaround was passing inventory IDs instead of names in
input_inventories. This fix makes names work the same wayorganizationscoping already works for the primary inventory lookup.I traced the root cause against the current
develbranch (verifiedresolve_name_to_id's only caller list before changing its signature) before writing the fix. Happy to adjust the approach if there's a preferred pattern I'm missing — this is my first contribution to AWX.Summary by CodeRabbit
Bug Fixes
Documentation