redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.13k stars 116 forks source link

Coroutine 'has_redisearch' was never awaited #531

Open khiemdoan opened 1 year ago

khiemdoan commented 1 year ago

I got this error without any detail or trace stack:

sys:1: RuntimeWarning: coroutine 'has_redisearch' was never awaited

I commented out these lines in aredis_om/model/model.py and my code run as I expected:

https://github.com/redis/redis-om-python/blob/87d3a080adf6e9dc2bda1b38204b5b341876f16e/aredis_om/model/model.py#L358-L363

# if not has_redisearch(model.db()):
#     raise RedisModelError(
#         "Your Redis instance does not have either the RediSearch module "
#         "or RedisJSON module installed. Querying requires that your Redis "
#         "instance has one of these modules installed."
#     )
bonastreyair commented 1 year ago

that is because the __init__() in the class is synchronous but the has_redissearch() method is async. A way to solve it would either change the class to have an async instance or to run that function using asyncio.run() check this source for more info. https://stackoverflow.com/questions/33128325/how-to-set-class-attribute-with-await-in-init