Skip to content
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 #273

Merged
Merged
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/273-Dont_call_get_on_None.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- digital_ocean_droplet - if the JSON response lacks a key and the associated variable is set to ``None``, then don't treat that variable like a ``dict`` and call ``get()`` on it without first testing it (https://github.com/ansible-collections/community.digitalocean/issues/272).
2 changes: 1 addition & 1 deletion plugins/modules/digital_ocean_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def wait_status(self, droplet_id, desired_statuses):
status_code = response.status_code
message = json_data.get("message", "no error message")
droplet = json_data.get("droplet", None)
droplet_status = droplet.get("status", None)
droplet_status = droplet.get("status", None) if droplet else None

if droplet is None or droplet_status is None:
self.module.fail_json(
Expand Down