Skip to content
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
6 changes: 3 additions & 3 deletions wikibaseintegrator/wbi_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,11 @@ def search_entities(search_string: str, language: str | None = None, strict_lang

language = str(language or config['DEFAULT_LANGUAGE'])

params = {
params: dict[str, str | int] = {
'action': 'wbsearchentities',
'search': search_string,
'language': language,
'type': search_type,
'limit': 50,
'format': 'json'
}

Expand All @@ -455,7 +454,8 @@ def search_entities(search_string: str, language: str | None = None, strict_lang
results = []

while True:
params.update({'continue': cont_count})
max_page_results = min(50, max_results - cont_count)
params.update({'continue': cont_count, 'limit': max_page_results})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More than open to style and logic suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, it seems we could move the cont_count < max_results criteria into the While condition above (and save 3 lines at the bottom of the function).

Comment on lines +457 to +458
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

The calculation max_results - cont_count can result in negative or zero values when cont_count >= max_results, which would cause max_page_results to be 0 or negative. This could lead to API errors or infinite loops. Add a check to break the loop when cont_count >= max_results before calculating max_page_results.

Copilot uses AI. Check for mistakes.

search_results = mediawiki_api_call_helper(data=params, allow_anonymous=allow_anonymous, **kwargs)

Expand Down
Loading