generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't throw an exception if API's JSON response lacks an expected key #272
Comments
coreywright
added a commit
to coreywright/community.digitalocean
that referenced
this issue
Jun 24, 2022
Instead of throwing an exception, be more defensive in the code: if the API's JSON response lacks a key and we correspondingly set a variable to `None`, then don't call `get()` on the variable, but test the variable first. AttributeError: 'NoneType' object has no attribute 'get' Fixes ansible-collections#272.
coreywright
added a commit
to coreywright/community.digitalocean
that referenced
this issue
Jun 24, 2022
Instead of throwing an exception, be more defensive in the code: if the API's JSON response lacks a key and we correspondingly set a variable to `None`, then don't call `get()` on the variable, but test the variable first. AttributeError: 'NoneType' object has no attribute 'get' Fixes ansible-collections#272.
coreywright
added a commit
to coreywright/community.digitalocean
that referenced
this issue
Jun 26, 2022
Instead of throwing an exception, be more defensive in the code: if the API's JSON response lacks a key and we correspondingly set a variable to `None`, then don't call `get()` on the variable, but test the variable first. AttributeError: 'NoneType' object has no attribute 'get' Fixes ansible-collections#272.
coreywright
changed the title
Don't throw an exception if API's JSON respose lacks an expected key
Don't throw an exception if API's JSON response lacks an expected key
Jun 26, 2022
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SUMMARY
If the DO API returns a JSON response with a missing key (eg
droplet
) or no keys, then don't set the associated variable toNone
(iedroplet = json_data.get("droplet", None)
) and immediately callget()
on it as if it's a dict (iedroplet_status = droplet.get("status", None)
).ISSUE TYPE
COMPONENT NAME
digital_ocean_droplet
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
digital_ocean_droplet
doesn't throw an exception, but gracefully handles the empty or incomplete API JSON response.ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: