fix: don't treat empty list response as a found resource in get_resource#343
Open
pfallasro wants to merge 1 commit into
Open
fix: don't treat empty list response as a found resource in get_resource#343pfallasro wants to merge 1 commit into
pfallasro wants to merge 1 commit into
Conversation
get_resource() stored the empty asset.*.List response wrapper (a dict containing an empty Results key) in api_response. Callers that guard on `if not api_response` then saw a truthy value and skipped their action; intersight_target_claim never sent the /asset/DeviceClaims POST, so unclaimed devices were never claimed (reported ok/changed:false). Only store a no-Results dict when the response has no 'Results' key at all (a GET by Moid). When a filtered list query returns an empty Results, clear api_response instead. Fixes CiscoDevNet#342 Signed-off-by: pfallasro <pfallasro@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #342
Problem
get_resource() stores an empty list-response wrapper as a found object. For a filtered query with no matches, Intersight returns a dict like {"ObjectType":"asset.Target.List","Results":[],"Count":0}. Because that dict is truthy, it was assigned to api_response.
Callers that guard on
if not api_responsethen treat "no match" as "resource exists" and skip their action. Concretely, intersight_target_claim (state: present) never sends the /asset/DeviceClaims POST for an unclaimed device: the task reports ok/changed:false while the device stays Not Claimed, with no error.Fix
Only store a no-Results dict when the response has no Results key at all (a GET by Moid returns the bare object). When a filtered list query returns an empty Results, clear api_response, matching the pre-existing "clear stale data" intent.
Impact
Testing
Verified end-to-end against a standalone CIMC server: with the fix, intersight_target_claim returns an asset.DeviceClaim object with changed:true and the device transitions to Claimed. Without the fix, the same play reports changed:false and the device stays Not Claimed.
A changelog fragment is included.