Comment 6 for bug 1817032

Revision history for this message
Mike Bayer (zzzeek) wrote :

I've added https://github.com/sqlalchemy/dogpile.cache/issues/144 to review this behavior and while 0.7's behavior is different, I think it is better:

from dogpile.cache import make_region

region = make_region().configure(
    'dogpile.cache.memory',
)

def load_user_info(value=0):
    return "hi"

import inspect

print(inspect.getfullargspec(load_user_info))

load_user_info = region.cache_on_arguments()(load_user_info)

print(inspect.getfullargspec(load_user_info))

print(load_user_info(value=5))

the above script in 0.7.x prints:

FullArgSpec(args=['value'], varargs=None, varkw=None, defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=['value'], varargs=None, varkw=None, defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={})
hi

that is, the argument signature is preserved perfectly and we see our load_user_info function acting identically as its non-cached version.

The old behavior looked like this:

FullArgSpec(args=['value'], varargs=None, varkw=None, defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=[], varargs='arg', varkw='kw', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
Traceback (most recent call last):
  File "test.py", line 21, in <module>
    print(load_user_info(value=5))
  File "/home/classic/dev/dogpile.cache/dogpile/cache/region.py", line 1262, in decorate
    key = key_generator(*arg, **kw)
  File "/home/classic/dev/dogpile.cache/dogpile/cache/util.py", line 37, in generate_key
    "dogpile.cache's default key creation "
ValueError: dogpile.cache's default key creation function does not accept keyword arguments.

this is because the argument signature was blown away so that the arg/kw were passed generically. you can still get the ValueError if you add `**kw` to the argument signature for load_user_info() and then add some extra keywords.

in short I think oslo.cache can remove the test case here as indicated in https://review.openstack.org/#/c/638732/, because you are not only testing dogpile, you're testing plain python / the decorator module.