From a28a8268c81f5da87da39bea6c74a6dc5c412ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 19 Jun 2023 15:23:18 +0200 Subject: [PATCH] Deprecate log method for report to store exception --- trytond/trytond/ir/cron.py | 2 +- trytond/trytond/ir/error.py | 10 ++++++++-- trytond/trytond/worker.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/trytond/trytond/ir/cron.py b/trytond/trytond/ir/cron.py index 4561347ca6..5ee3fceb32 100644 --- a/trytond/trytond/ir/cron.py +++ b/trytond/trytond/ir/cron.py @@ -199,7 +199,7 @@ class Cron(DeactivableMixin, ModelSQL, ModelView): logger.debug("Retry: %i", count) continue if isinstance(e, (UserError, UserWarning)): - Error.log(cron, e) + Error.report(cron, e) logger.info( "%s failed after %i ms", name, duration()) else: diff --git a/trytond/trytond/ir/error.py b/trytond/trytond/ir/error.py index 0c8ea1ba58..6c4e8da41b 100644 --- a/trytond/trytond/ir/error.py +++ b/trytond/trytond/ir/error.py @@ -3,6 +3,7 @@ import datetime as dt import functools import logging +import warnings from trytond.config import config from trytond.exceptions import UserError, UserWarning @@ -123,9 +124,14 @@ class Error(Workflow, ModelView, ModelSQL): # Test if it is a ModelStorage.log call if len(args) <= 1 or not isinstance(args[1], Exception): return super().log(*args, **kwargs) + warnings.warn( + "Call report instead of log to store exception", + DeprecationWarning) + cls.report(*args, **kwargs) + + @classmethod + def report(cls, origin, exception): try: - origin, exception = args - assert not kwargs assert isinstance(exception, (UserError, UserWarning)) with Transaction().new_transaction(autocommit=True): if not cls.search([ diff --git a/trytond/trytond/worker.py b/trytond/trytond/worker.py index 6a20bae1c2..8bcdfe0003 100644 --- a/trytond/trytond/worker.py +++ b/trytond/trytond/worker.py @@ -155,7 +155,7 @@ def run_task(pool, task_id): continue raise except (UserError, UserWarning) as e: - Error.log(task, e) + Error.report(task, e) raise logger.info("%s in %i ms", name, duration()) except backend.DatabaseOperationalError: