Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/342-get-resource-empty-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- module_utils - ``get_resource`` no longer stores an empty list-response wrapper as a found object. A filtered query with no matches now clears ``api_response`` instead of keeping the ``asset.*.List`` dict, so callers such as ``intersight_target_claim`` correctly detect an absent resource and perform the create/claim (https://github.com/CiscoDevNet/intersight-ansible/issues/342).
9 changes: 7 additions & 2 deletions plugins/module_utils/intersight.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,13 @@ def get_resource(self, resource_path, query_params, return_list=False):
# return the 1st list element
self.result['api_response'] = response['Results'][0]
else:
# Return a dict if no Results array (handles case where resource_path contains a Moid)
if isinstance(response, dict):
# A GET by Moid returns the object directly (a dict with no
# 'Results' key). A filtered list query with no matches returns a
# dict that DOES contain an (empty) 'Results' key; that is not a
# hit and must not be stored, otherwise callers that guard on
# `if not api_response` (e.g. intersight_target_claim) treat the
# empty result as an existing object and skip their action.
if isinstance(response, dict) and 'Results' not in response:
self.result['api_response'] = response
else:
# Clear api_response when no results found to prevent returning stale data
Expand Down
Loading