]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix beaker caching example to use new ".callable" param on bind
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Dec 2010 16:37:07 +0000 (11:37 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Dec 2010 16:37:07 +0000 (11:37 -0500)
examples/beaker_caching/caching_query.py

index a94eea6ac247a520d2cd2cf76927e86788a2c01c..d9ec1576ebeca79ed3ee3eee9e69114457d77b3d 100644 (file)
@@ -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})