From f3eaf75ed1ce51eb66aa63a9f9264f78fb6278dc Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Mon, 6 Oct 2014 12:34:51 +0200 Subject: [PATCH] Fixes hashing on Python 3. --- cachalot/monkey_patch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cachalot/monkey_patch.py b/cachalot/monkey_patch.py index a82f517..481097e 100644 --- a/cachalot/monkey_patch.py +++ b/cachalot/monkey_patch.py @@ -31,8 +31,12 @@ PATCHED = False MISS_VALUE = '[[Missing cache key]]' +def hash_cache_key(unicode_key): + return md5(unicode_key.encode('utf-8')).hexdigest() + + def _get_query_cache_key(compiler): - return md5('%s:%s' % compiler.as_sql()).hexdigest() + return hash_cache_key('%s:%s' % compiler.as_sql()) def _get_tables(query): @@ -45,7 +49,7 @@ def _get_tables(query): def _get_table_cache_key(table): - return md5('%s_queries' % table).hexdigest() + return hash_cache_key('%s_queries' % table) def _get_tables_cache_keys(query):