From be4e723b3f1fbf05f6ccf285495cad841dc12e0a Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Mon, 13 Oct 2014 20:57:36 +0200 Subject: [PATCH] Commits an atomic cache after a SQL commit (not before). --- cachalot/monkey_patch.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cachalot/monkey_patch.py b/cachalot/monkey_patch.py index 3dafb1d..3a88d75 100644 --- a/cachalot/monkey_patch.py +++ b/cachalot/monkey_patch.py @@ -240,13 +240,15 @@ def _patch_atomic(): 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() - if exc_type is None and not connection.needs_rollback: - atomic_cache.commit() + needs_rollback = connection.needs_rollback original(self, exc_type, exc_value, traceback) + nested_caches = NESTED_CACHES[cachalot_settings.CACHALOT_CACHE] + atomic_cache = nested_caches.pop() + if exc_type is None and not needs_rollback: + atomic_cache.commit() + inner.original = original return inner