sdispater / cachy

Cachy provides a simple yet effective caching library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle unpickling issues gracefully

mjpieters opened this issue · comments

I just had to switch a project that uses cachy to an earlier Python release (from 3.9 to 3.7), and now that project's build failed with:

Traceback (most recent call last):
[...]
  File "/.../lib/python3.7/site-packages/cachy/repository.py", line 47, in get
    val = self._store.get(key)
  File "/.../lib/python3.7/site-packages/cachy/stores/file_store.py", line 43, in get
    return self._get_payload(key).get('data')
  File "/.../lib/python3.7/site-packages/cachy/stores/file_store.py", line 75, in _get_payload
    data = self.unserialize(contents[10:])
  File "/.../lib/python3.7/site-packages/cachy/contracts/store.py", line 118, in unserialize
    return self._serializer.unserialize(data)
  File "/.../lib/python3.7/site-packages/cachy/serializers/pickle_serializer.py", line 43, in unserialize
    return loads(data)
ValueError: unsupported pickle protocol: 5

That's simply because the cached data is using a pickle protocol that Python 3.7 doesn't know about. Cachy should simply ignore these errors and instead treat the cache as missing.