algolia / algoliasearch-client-python

⚡️ A fully-featured and blazing-fast Python API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/python/?language=python
MIT License
196 stars 67 forks source link

fix(iterators): prevent recursion issue #542

Closed shortcuts closed 2 years ago

shortcuts commented 2 years ago
Q A
Bug fix? yes
New feature? no
BC breaks? no
Related Issue Support ticket
Need Doc update yes

Describe your change

if self._raw_response["nbHits"] < self._data["hitsPerPage"]: was never validated since nbHits does not represent the number of returned hits but the total of hits.

We now compute nbHits on the len(hits).

What problem is this fixing?

Recursion was never ending with iterations > 1000 hitsPerPage.

Reproduction

I've set an index (python_repro_rules) with 3k+ rules on this app (QPBQ67WNIG)

from algoliasearch.search_client import SearchClient, SearchConfig

config = SearchConfig('QPBQ67WNIG', 'SEARCH_API_KEY')
client = SearchClient.create_with_config(config)
index = client.init_index('python_repro_rules')

i = 0
for rule in index.browse_rules():
    print('called in main', i)
    i += 1