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
Open
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: 1 addition & 1 deletion internetarchive/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _scrape(self):
if j.get('error'):
yield j
if not num_found:
num_found = int(j['total'])
num_found = int(j['total'] or 0)
if not self._num_found:
self._num_found = num_found
Comment on lines +156 to 158
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

self._handle_scrape_error(j)
Expand Down