aio-libs / aiocache

Asyncio cache manager for redis, memcached and memory
http://aiocache.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.12k stars 154 forks source link

Cache.REDIS: issubclass() arg 1 must be a class #539

Open liquiddandruff opened 3 years ago

liquiddandruff commented 3 years ago

In trying https://stackoverflow.com/questions/65686318/sharing-python-objects-across-multiple-workers I've encountered this exception.

Seems hit same issue here: https://github.com/samuelcolvin/pydantic/issues/545#issuecomment-595983173

From docker stderr:

app_1    |   File "/app/./main.py", line 8, in <module>
app_1    |     cache = Cache(Cache.REDIS, endpoint="localhost", port=6379, namespace="main")
app_1    |   File "/usr/local/lib/python3.8/site-packages/aiocache/factory.py", line 65, in __new__
app_1    |     assert issubclass(cache_class, BaseCache)
app_1    | TypeError: issubclass() arg 1 must be a class

REPL:

>>> from aiocache import Cache
ujson module not found, using json
msgpack not installed, MsgPackSerializer unavailable
>>> Cache()
<aiocache.backends.memory.SimpleMemoryCache object at 0x1085fd820>
>>> Cache(Cache.REDIS)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/variant23/repos/mintad-validator/venv/lib/python3.8/site-packages/aiocache/factory.py", line 65, in __new__
    assert issubclass(cache_class, BaseCache)
TypeError: issubclass() arg 1 must be a class
>>> type(Cache.REDIS)
<class 'NoneType'>
>>> print(Cache.REDIS)
None
>>> print(Cache.MEMORY)
<class 'aiocache.backends.memory.SimpleMemoryCache'>

Packages:

aiocache==0.11.1
fastapi==0.65.1
pydantic==1.8.2

EDIT: Wasn't able to resolve the issue, ended up using aioredis instead.

ofirzh commented 3 years ago

add lib aioredis==1.3.1 to requirments.txt

ansidorov commented 3 years ago

I get a similar error:

>>> from aiocache import Cache
ujson module not found, using json
>>> Cache(Cache.MEMCACHED)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/slurm/py39/lib/python3.9/site-packages/aiocache/factory.py", line 65, in __new__
    assert issubclass(cache_class, BaseCache)
TypeError: issubclass() arg 1 must be a class

>>> Cache(Cache.MEMCACHED)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/slurm/py39/lib/python3.9/site-packages/aiocache/factory.py", line 65, in __new__
    assert issubclass(cache_class, BaseCache)
TypeError: issubclass() arg 1 must be a class

In this case, installing aiomcache helped: pip install aiomcache Although the README specifies other package names https://github.com/aio-libs/aiocache#id2

Dreamsorcerer commented 1 year ago

If someone wants to add a None check and produce a better error, that makes it clear you need to install the required libraries, that would be great.