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

Covid Dashboard: Change in Stats REST API none return value causes crash #3

Closed
edumorlom opened this issue Jun 4, 2020 · 2 comments

Comments

@edumorlom
Copy link
Contributor

edumorlom commented Jun 4, 2020

There was a breaking change to the return type of the Stats REST APIs that caused the server to crash with TypeError exception when trying to retrieve "data" from "None".

When making a request using the stats data commons REST APIs, if there was no data to return for a given dcid, it would drop the dcid from the response. Now, instead, it will return dcid->None, which caused issues when trying to read the data value.

Example of return type for dcid without a value:
IMG_7122

Exception Message:

data = response[dcid]['data']
TypeError: 'NoneType' object is not subscriptable

@edumorlom
Copy link
Contributor Author

The workaround is to try to retrieve the data, and if it fails due to TypeError exception because there is no data, continue to the next iteration.

for dcid in response:
   try:
      data = response[dcid]['data']
      data_holder[dcid] = data
   except TypeError:
         continue

@shifucun
Copy link
Contributor

shifucun commented Jun 4, 2020

It is helpful to handle null/empty data in key value retrieval. In this case, you can do:

for dcid in response:
if response[dcid] and 'data' in response[dcid]:
xxx
else:
logging.error('missing data ...')

@shifucun shifucun closed this as completed Jun 4, 2020
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

No branches or pull requests

2 participants