From f1c72ee8ee44c35707d5a18167eb8efeca3c4a6f Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Mar 2019 17:32:04 +0000 Subject: [PATCH] [FIX] base: fix ir.logging database locking when using --log-db Before this patch, the ir.logging's write_uid field was a many2one which could cause a module install/update to hang when the module is changing the res.users model schema and when this module causes to orm to warn through the logger. (eg: declaring two res.users fields with the same string attribute) In such situation the transaction cursor that is processing the res_users table alteration will be granted an exclusive postgresql lock hence causing the ir_logging insertion to block because of the write_uid foreign key to res_users. This issue has never been raised by runbot as it is using a remote database with --log-db Note: the write_uid conversion from m2o to int was left over in commit e6a5d82 closes odoo/odoo#32015 Signed-off-by: Christophe Simonis --- odoo/addons/base/ir/ir_logging.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/ir/ir_logging.py b/odoo/addons/base/ir/ir_logging.py index 0397bff7425..4e3caef0794 100644 --- a/odoo/addons/base/ir/ir_logging.py +++ b/odoo/addons/base/ir/ir_logging.py @@ -1,13 +1,27 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models class IrLogging(models.Model): _name = 'ir.logging' _order = 'id DESC' - create_date = fields.Datetime(readonly=True) - create_uid = fields.Integer(string='Uid', readonly=True) # Integer not m2o is intentionnal + # The _log_access fields are defined manually for the following reasons: + # + # - The entries in ir_logging are filled in with sql queries bypassing the orm. As the --log-db + # cli option allows to insert ir_logging entries into a remote database, the one2many *_uid + # fields make no sense in the first place but we will keep it for backward compatibility. + # + # - Also, when an ir_logging entry is triggered by the orm (when using --log-db) at the moment + # it is making changes to the res.users model, the ALTER TABLE will aquire an exclusive lock + # on res_users, preventing the ir_logging INSERT to be processed, hence the ongoing module + # install/update will hang forever as the orm is blocked by the ir_logging query that will + # never occur. + create_uid = fields.Integer(string='Created by', readonly=True) + create_date = fields.Datetime(string='Created on', readonly=True) + write_uid = fields.Integer(string='Last Updated by', readonly=True) + write_date = fields.Datetime(string='Last Updated on', readonly=True) + name = fields.Char(required=True) type = fields.Selection([('client', 'Client'), ('server', 'Server')], required=True, index=True) dbname = fields.Char(string='Database Name', index=True) @@ -16,3 +30,8 @@ class IrLogging(models.Model): path = fields.Char(required=True) func = fields.Char(string='Function', required=True) line = fields.Char(required=True) + + @api.model_cr + def init(self): + super(IrLogging, self).init() + self._cr.execute("ALTER TABLE ir_logging DROP CONSTRAINT IF EXISTS ir_logging_write_uid_fkey")