Skip to content

fix: don't treat empty list response as a found resource in get_resource#343

Open
pfallasro wants to merge 1 commit into
CiscoDevNet:mainfrom
pfallasro:fix/get-resource-empty-list-342
Open

fix: don't treat empty list response as a found resource in get_resource#343
pfallasro wants to merge 1 commit into
CiscoDevNet:mainfrom
pfallasro:fix/get-resource-empty-list-342

Conversation

@pfallasro

Copy link
Copy Markdown

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_response then 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

  • Fixes claiming of new devices via intersight_target_claim.
  • GET-by-Moid behavior is unchanged (still returns the bare object dict).
  • Modules that create-if-absent via a filtered pre-check now correctly detect absence.

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intersight_target_claim silently skips claim for unclaimed devices (get_resource stores empty List wrapper)

1 participant