Skip to content

Pickle transform is not stable between attrs releases #140

@layday

Description

@layday

aiohttp-client-cache responses are attrs instances which are pickled for storage by the base backend. The latest attrs release made changes to __{g,s}etstate__, i.e. to the way that frozen attrs classes are transformed for pickling, such that responses which were serialised by attrs 22.1.0 are incompatible with attrs 22.2.0. When using attrs 22.2.0 and attempting to report the cache status of a response which was serialised by an earlier version of attrs, aiohttp-client-cache will error with:

[...]
  File "/[...]/venv/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/[...]/venv/lib/python3.11/site-packages/forge/_revision.py", line 322, in inner
    return await callable(*mapped.args, **mapped.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/venv/lib/python3.11/site-packages/aiohttp_client_cache/session.py", line 46, in _request
    response, actions = await self.cache.request(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/venv/lib/python3.11/site-packages/aiohttp_client_cache/backends/base.py", line 127, in request
    response = None if actions.skip_read else await self.get_response(actions.key)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/venv/lib/python3.11/site-packages/aiohttp_client_cache/backends/base.py", line 142, in get_response
    elif not await self.is_cacheable(response):  # type: ignore
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[...]/venv/lib/python3.11/site-packages/aiohttp_client_cache/backends/base.py", line 86, in is_cacheable
    'disabled method': str(response.method) not in self.allowed_methods,
                           ^^^^^^^^^^^^^^^
AttributeError: 'CachedResponse' object has no attribute 'method'

As far as I can tell, this code path is always hit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions