From b23000c66017e49615a3226fd7d8682a408aa444 Mon Sep 17 00:00:00 2001 From: Morgan Fainberg Date: Fri, 14 Dec 2018 14:46:40 -0800 Subject: [PATCH] Fix dogpile.cache 0.7.0 interaction Due to the change in behavior in dogpile.cache > 0.7.0 where bound methods can no longer be passed to the cache_on_arguments decorator, openstackSDK now explicitly provides a non-method wrapper for all elements passed to cache_on_arguments. This is handled via an explicit no-op decorator. functools.wraps is used to preserve data from the original method. Needed-By: https://review.openstack.org/#/c/624993 Change-Id: Ied27fa1e834d145246815afcb67c59d48669ffb2 Story: 2004605 Task: 28502 --- shade/_utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/shade/_utils.py b/shade/_utils.py index 3ca54d128..9cf566d67 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -14,6 +14,7 @@ import contextlib import fnmatch +import functools import inspect import jmespath import munch @@ -414,6 +415,18 @@ def valid_kwargs(*valid_args): return func_wrapper +def _func_wrap(f): + # NOTE(morgan): This extra wrapper is intended to eliminate ever + # passing a bound method to dogpile.cache's cache_on_arguments. In + # 0.7.0 and later it is impossible to pass bound methods to the + # decorator. This was introduced when utilizing the decorate module in + # lieu of a direct wrap implementation. + @functools.wraps(f) + def inner(*args, **kwargs): + return f(*args, **kwargs) + return inner + + def cache_on_arguments(*cache_on_args, **cache_on_kwargs): _cache_name = cache_on_kwargs.pop('resource', None) @@ -421,7 +434,7 @@ def cache_on_arguments(*cache_on_args, **cache_on_kwargs): def _cache_decorator(obj, *args, **kwargs): the_method = obj._get_cache(_cache_name).cache_on_arguments( *cache_on_args, **cache_on_kwargs)( - func.__get__(obj, type(obj))) + _func_wrap(func.__get__(obj, type(obj)))) return the_method(*args, **kwargs) def invalidate(obj, *args, **kwargs):