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

Fix TypeError when iterating over 0 search results #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DuncanDHall
Copy link
Contributor

@DuncanDHall DuncanDHall commented Apr 3, 2023

Scrape can result in j where 'count': 0, 'total': None resulting in:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Scrape can result in `j` where `count: 0, total: None` resulting in:
`TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'`
Comment on lines +156 to 158
num_found = int(j['total'] or 0)
if not self._num_found:
self._num_found = num_found
Copy link
Contributor

@cclauss cclauss Apr 7, 2023

Choose a reason for hiding this comment

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

It would be awesome if we had an empty search test case that failed with the current code and passed with the proposed code.

The GitHub Actions tests have been updated so another push to the pull request should pass all GitHub Actions.

Please remove line 155 and then...

Suggested change
num_found = int(j['total'] or 0)
if not self._num_found:
self._num_found = num_found
num_found = num_found or int(j['total'] or 0)
self._num_found = self._num_found or num_found

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.

2 participants