]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed a long-standing bug in the caching example, where
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Apr 2013 00:11:08 +0000 (20:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Apr 2013 00:11:08 +0000 (20:11 -0400)
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.

doc/build/changelog/changelog_08.rst
examples/dogpile_caching/caching_query.py

index 25a8d4c1909fd09942a43d0468118389216d3835..0cf5e1f13cc6701e4ea9bb29ec24051552849827 100644 (file)
@@ -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
index 81ca310606c826df626d2f794fdc647d320e742a..f4724fb0b6d139fca43a18a134ce7a7c5f122207 100644 (file)
@@ -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."""