Deprecate log method for report to store exception
This commit is contained in:
1 parent
6b9f87c4b3
commit
a28a8268c8
3 files changed
+10
-4
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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([
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user