[IMP] base: new cr for log method
The `log` method of a server action uses the same cursor than the transaction. Therefore, if an error is raised during the server action execution, the log messages are lost since the transaction is rolled back. We introduce a new cursor in the `log` method, so the log messages are kept even when an exception is raised. opw-704036
This commit is contained in:
@@ -896,10 +896,11 @@ class IrActionsServer(models.Model):
|
||||
:type action: browse record
|
||||
:returns: dict -- evaluation context given to (safe_)safe_eval """
|
||||
def log(message, level="info"):
|
||||
self._cr.execute("""
|
||||
INSERT INTO ir_logging(create_date, create_uid, type, dbname, name, level, message, path, line, func)
|
||||
VALUES (NOW() at time zone 'UTC', %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
""", (self.env.uid, 'server', self._cr.dbname, __name__, level, message, "action", action.id, action.name))
|
||||
with self.pool.cursor() as cr:
|
||||
cr.execute("""
|
||||
INSERT INTO ir_logging(create_date, create_uid, type, dbname, name, level, message, path, line, func)
|
||||
VALUES (NOW() at time zone 'UTC', %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
""", (self.env.uid, 'server', self._cr.dbname, __name__, level, message, "action", action.id, action.name))
|
||||
|
||||
eval_context = super(IrActionsServer, self)._get_eval_context(action=action)
|
||||
model = self.env[action.model_id.model]
|
||||
|
||||
Reference in New Issue
Block a user