From 05ba0a10ffa452d88705bf7408804873b9cbbe83 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 16 May 2020 11:31:59 +0200 Subject: [PATCH 1/2] misc: add settings to propagate exceptions in hooks (#42982) --- src/authentic2/hooks.py | 4 ++++ tests/settings.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/authentic2/hooks.py b/src/authentic2/hooks.py index 0212c050..2125a280 100644 --- a/src/authentic2/hooks.py +++ b/src/authentic2/hooks.py @@ -54,6 +54,8 @@ def call_hooks(hook_name, *args, **kwargs): try: yield hook(*args, **kwargs) except Exception: + if getattr(settings, 'A2_HOOKS_PROPAGATE_EXCEPTIONS', False): + raise logger.exception(u'exception while calling hook %s', hook) @@ -67,4 +69,6 @@ def call_hooks_first_result(hook_name, *args, **kwargs): if result is not None: return result except Exception: + if getattr(settings, 'A2_HOOKS_PROPAGATE_EXCEPTIONS', False): + raise logger.exception(u'exception while calling hook %s', hook) diff --git a/tests/settings.py b/tests/settings.py index ebdfd27c..18e319d9 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -45,6 +45,8 @@ A2_AUTH_KERBEROS_ENABLED = False A2_VALIDATE_EMAIL_DOMAIN = False +A2_HOOKS_PROPAGATE_EXCEPTIONS = True + TEMPLATES[0]['DIRS'].append('tests/templates') TEMPLATES[0]['OPTIONS']['debug'] = True -- 2.26.2