summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-18 20:11:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-18 20:11:08 -0400
commitb6bf8c2a3001c38684ef806678dd187926e1910b (patch)
treed26137ca93535ec0402b236004e5daaef3519542 /examples
parent23c43e94b0d7c5d69595d63cc205f3c08fe78fa3 (diff)
downloadsqlalchemy-b6bf8c2a3001c38684ef806678dd187926e1910b.tar.gz
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.
Diffstat (limited to 'examples')
-rw-r--r--examples/dogpile_caching/caching_query.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/examples/dogpile_caching/caching_query.py b/examples/dogpile_caching/caching_query.py
index 81ca31060..f4724fb0b 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."""