Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
71b3c834 by Cédric Krier at 2023-06-21T11:11:25+02:00
Manage naming collision for log method on ir.error
Since a2eaa8f46096, ModelStorage has a generic log method which collides with
the exiting log method introduced in f6b0d437b5b6.
For backward compatibility we test the arguments to decide which version is
actually called.
Closes #12333
- - - - -
071c5f7d by Cédric Krier at 2023-06-19T15:23:18+02:00
Deprecate log method for report to store exception
- - - - -
3 changed files:
- trytond/trytond/ir/cron.py
- trytond/trytond/ir/error.py
- trytond/trytond/worker.py
Changes:
=====================================
trytond/trytond/ir/cron.py
=====================================
@@ -199,7 +199,7 @@
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:
=====================================
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
@@ -6,7 +7,8 @@
from trytond.config import config
from trytond.exceptions import UserError, UserWarning
-from trytond.model import Index, ModelSQL, ModelView, Workflow, fields
+from trytond.model import (
+ Index, ModelSQL, ModelView, Workflow, dualmethod, fields)
from trytond.pool import Pool
from trytond.pyson import Eval
from trytond.tools import firstline
@@ -117,4 +119,14 @@
return "%s - %s" % (self.origin_string, self.origin.rec_name)
return super().get_rec_name(name)
+ @dualmethod
+ def log(cls, *args, **kwargs):
+ # 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
@@ -120,5 +132,5 @@
@classmethod
- def log(cls, origin, exception):
+ def report(cls, origin, exception):
try:
assert isinstance(exception, (UserError, UserWarning))
with Transaction().new_transaction(autocommit=True):
=====================================
trytond/trytond/worker.py
=====================================
@@ -155,7 +155,7 @@
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:
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/71b6e977dd41028ceea5586b01aaaf52f4df3055...071c5f7daa18d876f46cd4606115da954ae429fd
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/71b6e977dd41028ceea5586b01aaaf52f4df3055...071c5f7daa18d876f46cd4606115da954ae429fd
You're receiving this email because of your account on foss.heptapod.net.