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

Conversation

coreywright
Copy link
Contributor

SUMMARY

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 #272.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

digital_ocean_droplet

ADDITIONAL INFORMATION
AttributeError: 'NoneType' object has no attribute 'get'

@coreywright coreywright temporarily deployed to integration June 24, 2022 18:55 Inactive
@coreywright coreywright force-pushed the bugfix-Dont_call_get_on_None branch from 25142d6 to 4433eec Compare June 24, 2022 18:56
@codecov
Copy link

codecov bot commented Jun 24, 2022

Codecov Report

Merging #273 (5cb930f) into main (b551430) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #273   +/-   ##
=======================================
  Coverage   68.24%   68.24%           
=======================================
  Files          45       45           
  Lines        3549     3549           
  Branches      752      752           
=======================================
  Hits         2422     2422           
  Misses        801      801           
  Partials      326      326           
Flag Coverage Δ
integration 67.63% <100.00%> (ø)
sanity 26.48% <0.00%> (ø)
units 64.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
plugins/modules/digital_ocean_droplet.py 68.69% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b551430...5cb930f. Read the comment docs.

@coreywright coreywright temporarily deployed to integration June 24, 2022 20:57 Inactive
Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, small fixes to the changelog fragment.

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 coreywright force-pushed the bugfix-Dont_call_get_on_None branch from 4433eec to 5cb930f Compare June 26, 2022 00:18
@coreywright coreywright temporarily deployed to integration June 26, 2022 00:18 Inactive
@coreywright
Copy link
Contributor Author

force pushed new commit to address comment(s) about changelog fragment.

@coreywright coreywright requested a review from mamercad June 26, 2022 21:31
Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks!

@mamercad mamercad merged commit 89a0fb1 into ansible-collections:main Jun 27, 2022
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.

Don't throw an exception if API's JSON response lacks an expected key
2 participants