Skip to content

RedisBackend should probably not raise errors #189

@youtux

Description

@youtux

I find it a little bit inconsistent the fact that the RedisBackend can raise errors while trying to get a value from the cache.
In comparison, the MemcachedBackend doesn't raise any error.
Dogpile.cache is about caching, I think it should do best-effort to try to get the value from the cache, but it should not raise exceptions in case of errors while getting the value.

This example shows the issue.

from dogpile.cache import make_region
import sys

print(sys.version)

region = make_region().configure(
    'dogpile.cache.redis',
    arguments = {'url': "redis://127.0.0.1"},
)

@region.cache_on_arguments()
def get_something(n):
    return {'foo': 'bar'}


get_something(1)
get_something(1)

Just run it in 2 different python versions that have a different pickle.HIGHEST_PROTOCOL defined, like python2.7 and python3.6 for example:

$ python3.6 script.py
3.6.11 (default, Jul 28 2020, 14:47:23) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.62)]
$ python2.7 script.py
2.7.17 (default, Feb 13 2020, 16:04:56) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)]
Traceback (most recent call last):
  File "/Users/youtux/Library/Application Support/JetBrains/PyCharm2020.2/scratches/script.py", line 16, in <module>
    get_something(1)
  File "</tmp/env/lib/python2.7/site-packages/decorator.pyc:decorator-gen-1>", line 2, in get_something
  File "/tmp/env/lib/python2.7/site-packages/dogpile/cache/region.py", line 1360, in get_or_create_for_user_func
    key, user_func, timeout, should_cache_fn, (arg, kw)
  File "/tmp/env/lib/python2.7/site-packages/dogpile/cache/region.py", line 962, in get_or_create
    async_creator,
  File "/tmp/env/lib/python2.7/site-packages/dogpile/lock.py", line 187, in __enter__
    return self._enter()
  File "/tmp/env/lib/python2.7/site-packages/dogpile/lock.py", line 87, in _enter
    value = value_fn()
  File "/tmp/env/lib/python2.7/site-packages/dogpile/cache/region.py", line 902, in get_value
    value = self.backend.get(key)
  File "/tmp/env/lib/python2.7/site-packages/dogpile/cache/backends/redis.py", line 154, in get
    return pickle.loads(value)
ValueError: unsupported pickle protocol: 4

Dogpile cache version: 0.9.0 (but the same happens with the latest version, 1.0.2)

I can make a PR if you think the behaviour should be more best-effort.

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