evaluate: log exception when on_raise is used (#59997)

This commit is contained in:
Benjamin Dauvergne 2021-12-22 10:40:44 +01:00
parent 8434dc2867
commit abf3ca8038
3 changed files with 7 additions and 1 deletions

View File

@ -298,6 +298,7 @@ def evaluate_condition(expression, ctx=None, validator=None, on_raise=None):
)
except Exception as e:
if on_raise is not None:
logger.exception('evaluate_condition: %s ctx=%r', expression, ctx)
return on_raise
raise e

View File

@ -82,7 +82,7 @@ def test_show_condition(db, app, settings, caplog):
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
response = app.get('/login/')
assert 'name="login-password-submit"' in response
assert len(caplog.records) == 0
assert len(caplog.records) == 1
def test_show_condition_service(db, app, settings):

View File

@ -91,6 +91,11 @@ def test_evaluate_condition(rf):
assert evaluate_condition('a < 1', on_raise=False) is False
def test_evaluate_condition_log_exception(caplog):
assert evaluate_condition('a < 1', on_raise=False) is False
assert 'evaluate_condition:' in caplog.records[0].message
def test_http_headers(rf):
request = rf.get('/', HTTP_X_ENTROUVERT='1')
headers = HTTPHeaders(request)