From: Mike Bayer Date: Wed, 22 Dec 2010 16:37:07 +0000 (-0500) Subject: - fix beaker caching example to use new ".callable" param on bind X-Git-Tag: rel_0_7b1~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=993af53204a0e4378fbf65a0bbf9a617e34dede1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fix beaker caching example to use new ".callable" param on bind --- diff --git a/examples/beaker_caching/caching_query.py b/examples/beaker_caching/caching_query.py index a94eea6ac2..d9ec1576eb 100644 --- a/examples/beaker_caching/caching_query.py +++ b/examples/beaker_caching/caching_query.py @@ -118,12 +118,14 @@ def _get_cache_parameters(query): region, namespace, cache_key = query._cache_parameters namespace = _namespace_from_query(namespace, query) - + if cache_key is None: # cache key - the value arguments from this query's parameters. args = _params_from_query(query) cache_key = " ".join([str(x) for x in args]) - + + assert cache_key is not None, "Cache key was None !" + # get cache cache = query.cache_manager.get_cache_region(namespace, region) @@ -253,14 +255,17 @@ def _params_from_query(query): """ v = [] def visit_bindparam(bind): - value = query._params.get(bind.key, bind.value) - # lazyloader may dig a callable in here, intended - # to late-evaluate params after autoflush is called. - # convert to a scalar value. - if callable(value): - value = value() - + if bind.key in query._params: + value = query._params[bind.key] + elif bind.callable: + # lazyloader may dig a callable in here, intended + # to late-evaluate params after autoflush is called. + # convert to a scalar value. + value = bind.callable() + else: + value = bind.value + v.append(value) if query._criterion is not None: visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam})