diff --git a/django_replicated/middleware.py b/django_replicated/middleware.py index f9bc7cf..220a135 100644 --- a/django_replicated/middleware.py +++ b/django_replicated/middleware.py @@ -96,6 +96,10 @@ def process_response(self, request, response): routers.reset() return response + def process_exception(self, request, exception): + if settings.REPLICATED_RESET_ON_EXCEPTION: + routers.reset() + def check_state_override(self, request, state): ''' Used to check if a web request should use a master or slave diff --git a/django_replicated/settings.py b/django_replicated/settings.py index 64d51a1..c5a6642 100644 --- a/django_replicated/settings.py +++ b/django_replicated/settings.py @@ -31,5 +31,8 @@ # Status codes on which set cookie for read-after-write workaround REPLICATED_FORCE_MASTER_COOKIE_STATUS_CODES = (302, 303) +# Reset state on exception in request +REPLICATED_RESET_ON_EXCEPTION = False + REPLICATED_MANAGE_ATOMIC_REQUESTS = False