From 7c5eea8df12a3b6c28d536da3fdba90e2f0c1d9e Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Mon, 6 Oct 2014 00:58:39 +0200 Subject: [PATCH] Uses ``wraps`` to be able to pickle patched methods. --- cachalot/monkey_patch.py | 9 ++++++++- cachalot/settings.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cachalot/monkey_patch.py b/cachalot/monkey_patch.py index 05bed32..e4c5e1d 100644 --- a/cachalot/monkey_patch.py +++ b/cachalot/monkey_patch.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from collections import defaultdict, Iterable +from functools import wraps import re from django.conf import settings @@ -69,7 +70,7 @@ def _invalidate_tables(cache, query): def clear_cache(cache): tables = connection.introspection.table_names() - tables_cache_keys = [_get_table_cache_key(t) for t in tables] + tables_cache_keys = [_get_table_cache_key(t) for t in tables] _invalidate_tables_cache_keys(cache, tables_cache_keys) @@ -162,6 +163,7 @@ def get_cache(): def _patch_orm_read(): def patch_execute_sql(original): + @wraps(original) def inner(compiler, *args, **kwargs): if not cachalot_settings.CACHALOT_ENABLED \ or isinstance(compiler, WRITE_COMPILERS): @@ -201,6 +203,7 @@ def _patch_orm_read(): def _patch_orm_write(): def patch_execute_sql(original): + @wraps(original) def inner(compiler, *args, **kwargs): _invalidate_tables(get_cache(), compiler.query) return original(compiler, *args, **kwargs) @@ -214,6 +217,7 @@ def _patch_orm_write(): def _patch_atomic(): def patch_enter(original): + @wraps(original) def inner(self): nested_caches = NESTED_CACHES[cachalot_settings.CACHALOT_CACHE] nested_caches.append(AtomicCache()) @@ -223,6 +227,7 @@ def _patch_atomic(): return inner def patch_exit(original): + @wraps(original) def inner(self, exc_type, exc_value, traceback): nested_caches = NESTED_CACHES[cachalot_settings.CACHALOT_CACHE] atomic_cache = nested_caches.pop() @@ -240,6 +245,7 @@ def _patch_atomic(): def _patch_test_db(): def patch_creation(original): + @wraps(original) def inner(*args, **kwargs): out = original(*args, **kwargs) clear_all_caches() @@ -249,6 +255,7 @@ def _patch_test_db(): return inner def patch_destruction(original): + @wraps(original) def inner(*args, **kwargs): clear_all_caches() return original(*args, **kwargs) diff --git a/cachalot/settings.py b/cachalot/settings.py index a86be2b..2c13620 100644 --- a/cachalot/settings.py +++ b/cachalot/settings.py @@ -1,3 +1,4 @@ +from functools import wraps from django.conf import settings @@ -16,6 +17,7 @@ class SettingsOverrider(object): setattr(self.settings, k, v) def __call__(self, func): + @wraps(func) def inner(*args, **kwargs): with self: return func(*args, **kwargs)