Commits

Marcin Kuzminski committed bf8ed0a

fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys

  • Participants
  • Parent commits 9f0fe67

Comments (0)

Files changed (3)

File docs/changelog.rst

 - fixes #368 improved git-protocol detection to handle other clients
 - fixes #366 When Setting Repository Group To Blank Repo Group Wont Be 
   Moved To Root
+- fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys 
+
 
 1.3.1 (**2012-02-27**)
 ----------------------

File rhodecode/lib/caching_query.py

 from sqlalchemy.orm.interfaces import MapperOption
 from sqlalchemy.orm.query import Query
 from sqlalchemy.sql import visitors
+from rhodecode.lib import safe_str
 
 
 class CachingQuery(Query):
 
     if cache_key is None:
         # cache key - the value arguments from this query's parameters.
-        args = [str(x) for x in _params_from_query(query)]
-        args.extend(filter(lambda k:k not in ['None', None, u'None'],
+        args = [safe_str(x) for x in _params_from_query(query)]
+        args.extend(filter(lambda k: k not in ['None', None, u'None'],
                            [str(query._limit), str(query._offset)]))
+
         cache_key = " ".join(args)
 
     if cache_key is None:

File rhodecode/model/db.py

 from rhodecode.lib.caching_query import FromCache
 
 from rhodecode.model.meta import Base, Session
+import hashlib
 
 
 log = logging.getLogger(__name__)
 # BASE CLASSES
 #==============================================================================
 
+_hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest()
+
 
 class ModelSerializer(json.JSONEncoder):
     """
             q = cls.query().filter(cls.username == username)
 
         if cache:
-            q = q.options(FromCache("sql_cache_short",
-                                    "get_user_%s" % username))
+            q = q.options(FromCache(
+                            "sql_cache_short",
+                            "get_user_%s" % _hash_key(username)
+                          )
+            )
         return q.scalar()
 
     @classmethod
         else:
             q = cls.query().filter(cls.users_group_name == group_name)
         if cache:
-            q = q.options(FromCache("sql_cache_short",
-                                    "get_user_%s" % group_name))
+            q = q.options(FromCache(
+                            "sql_cache_short",
+                            "get_user_%s" % _hash_key(group_name)
+                          )
+            )
         return q.scalar()
 
     @classmethod
             gr = cls.query()\
                 .filter(cls.group_name == group_name)
         if cache:
-            gr = gr.options(FromCache("sql_cache_short",
-                                          "get_group_%s" % group_name))
+            gr = gr.options(FromCache(
+                            "sql_cache_short",
+                            "get_group_%s" % _hash_key(group_name)
+                            )
+            )
         return gr.scalar()
 
     @property