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

SearchIndex.browse_objects_async doesn't work, ObjectIteratorAsync.__aiter__ not awaited? #559

Open jonathansick opened 1 year ago

jonathansick commented 1 year ago

Description

I'm trying to use SearchIndex.browse_objects_async, but I'm running into an issue with the async iterator, ObjectIteratorAsync.

This is the exception traceback I get:

    async for hit in index.browse_objects_async(
TypeError: 'async for' received an object from __aiter__ that does not implement __anext__: coroutine

When I run the example below I also get a RuntimeWarning:

RuntimeWarning: coroutine 'ObjectIteratorAsync.__aiter__' was never awaited
  async for hit in index.browse_objects_async(

It seems like the issue is with how browse_objects_async is creating the ObjectIteratorAsync.

Note that I can switch to a sync version of the API and it runs fine. Async would be appreciated here though. 😄

Steps To Reproduce

import asyncio
from os import getenv

from algoliasearch.search_client import SearchClient

async def main() -> None:
    async with SearchClient.create(
        getenv("ALGOLIA_APP_ID"), getenv("ALGOLIA_API_KEY")
    ) as client:
        index = client.init_index("MY_INDEX")
        async for hit in index.browse_objects_async(
            {"attributesToRetrieve": []}
        ):
            print(hit)

if __name__ == "__main__":
    asyncio.run(main())