Skip to content

Redis cache decorator fail on Python3.11 #761

@n-chatchai

Description

@n-chatchai

Given sample code,

import asyncio

from collections import namedtuple
import redis.asyncio as redis

from aiocache import cached, Cache
from aiocache.serializers import PickleSerializer

Result = namedtuple("Result", "content, status")


@cached(
    ttl=10,
    cache=Cache.REDIS,
    key_builder=lambda *args, **kw: "key",
    serializer=PickleSerializer(),
    namespace="main",
    client=redis.Redis(),
)
async def cached_call():
    return Result("content", 200)


async def test_cached():
    async with Cache(Cache.REDIS, namespace="main", client=redis.Redis()) as cache:
        await cached_call()
        exists = await cache.exists("key")
        assert exists is True
        await cache.delete("key")


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

Steps.

  1. python -m venv .venv
  2. source .venv/bin/activate
  3. python -m pip install 'aiocache[redis]'
  4. python cache.py

Result

Traceback (most recent call last):
  File "/Users/xxxx/cache.py", line 12, in <module>
    @cached(
     ^^^^^^^
  File "/Users/xxxx/.venv/lib/python3.11/site-packages/aiocache/decorators.py", line 99, in __call__
    self.cache = _get_cache(
                 ^^^^^^^^^^^
  File "/Users/xxxx/.venv/lib/python3.11/site-packages/aiocache/decorators.py", line 238, in _get_cache
    return Cache(cache, serializer=serializer, plugins=plugins, **cache_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxx/.venv/lib/python3.11/site-packages/aiocache/factory.py", line 68, in __new__
    instance.__init__(**kwargs)
  File "/Users/xxxx/.venv/lib/python3.11/site-packages/aiocache/backends/redis.py", line 203, in __init__
    super().__init__(serializer=serializer or JsonSerializer(), **kwargs)
  File "/Users/xxxx/.venv/lib/python3.11/site-packages/aiocache/backends/redis.py", line 46, in __init__
    super().__init__(**kwargs)
TypeError: BaseCache.__init__() got an unexpected keyword argument 'client'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions