From 96812b3a6d9ad62ed5bfd62a75c0ba5c13f4bf6b Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Mon, 30 Oct 2023 11:37:05 +0100 Subject: [PATCH] fixup! sf_base: add decorator to gracefully handle exceptions --- shopfloor_base/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shopfloor_base/utils.py b/shopfloor_base/utils.py index befac317e9..a3e0aeb396 100644 --- a/shopfloor_base/utils.py +++ b/shopfloor_base/utils.py @@ -43,15 +43,18 @@ def catch_errors(response_error): def _catch_errors(fn): @wraps(fn) - def wrapper(*args, **kwargs): + def wrapper(self, *args, **kwargs): + savepoint = self._actions_for("savepoint").new() try: - res = fn(*args, **kwargs) + res = fn(self, *args, **kwargs) except ValidationError as ex: + savepoint.rollback() message = { "message_type": "error", "body": ex.name, } - return response_error(*args, **kwargs, message=message) + return response_error(self, *args, **kwargs, message=message) + savepoint.release() return res return wrapper