From: Mike Bayer Date: Fri, 19 Apr 2013 00:11:08 +0000 (-0400) Subject: Fixed a long-standing bug in the caching example, where X-Git-Tag: rel_0_8_1~13^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6bf8c2a3001c38684ef806678dd187926e1910b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixed a long-standing bug in the caching example, where the limit/offset parameter values wouldn't be taken into account when computing the cache key. The _key_from_query() function has been simplified to work directly from the final compiled statement in order to get at both the full statement as well as the fully processed parameter list. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 25a8d4c190..0cf5e1f13c 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,17 @@ .. changelog:: :version: 0.8.1 + .. change:: + :tags: bug, examples + + Fixed a long-standing bug in the caching example, where + the limit/offset parameter values wouldn't be taken into + account when computing the cache key. The + _key_from_query() function has been simplified to work + directly from the final compiled statement in order to get + at both the full statement as well as the fully processed + parameter list. + .. change:: :tags: bug, mssql :tickets: 2355 diff --git a/examples/dogpile_caching/caching_query.py b/examples/dogpile_caching/caching_query.py index 81ca310606..f4724fb0b6 100644 --- a/examples/dogpile_caching/caching_query.py +++ b/examples/dogpile_caching/caching_query.py @@ -136,24 +136,15 @@ def _key_from_query(query, qualifier=None): """ - v = [] - def visit_bindparam(bind): - - if bind.key in query._params: - value = query._params[bind.key] - elif bind.callable: - value = bind.callable() - else: - value = bind.value - - v.append(unicode(value)) - stmt = query.statement - visitors.traverse(stmt, {}, {'bindparam': visit_bindparam}) + compiled = stmt.compile() + params = compiled.params # here we return the key as a long string. our "key mangler" # set up with the region will boil it down to an md5. - return " ".join([unicode(stmt)] + v) + return " ".join( + [unicode(compiled)] + + [unicode(params[k]) for k in sorted(params)]) class FromCache(MapperOption): """Specifies that a Query should load results from a cache."""