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

int vs dict - unhandled response #541

Open pkucmus opened 2 years ago

pkucmus commented 2 years ago

Description

On a rare occasion MultipleIndexBatchIndexingResponse instance's wait call throws AttributeError 'int' object has no attribute 'items'. This is caused by get_items trying to iterate over self.raw_response["taskID"] which for some reason is an int.

    def wait(self, request_options=None):
        # type: (Optional[Union[RequestOptions, dict]]) -> MultipleIndexBatchIndexingResponse # noqa: E501

        while not self._done:
            for index_name, task_id in get_items(self.raw_response["taskID"]):  # <--------
                self._client._sync().wait_task(index_name, task_id, request_options)
            self._done = True

        return self

Steps To Reproduce

I honestly don't know how to trigger this behavior. Apparently the API allows mixed types in the taskID field (int or object) which causes this behavior - how to trigger the API to respond with an int there is unknown to me.

Thanks