From cedc968f22a2f6d85f736a7dc223569c84267e3d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 11 Apr 2023 11:08:03 +0000 Subject: [PATCH] [FIX] base: better filter drop table warnings Along with improving the table_kind API, #117439 added a warning when dropping non-tables. This warning turns out to trigger on many models, in two major cases: - the hook is called on abstract models, which don't have a table in the first place, it probably should not be called for those but can easily be skipped - the hook is also called on `_auto = False` which don't have a table anymore, this is because we use `DROP TABLE $table CASCADE`, which implicitly drops any view (or table) depending on the table, it might be possible to avoid this by ensuring we drop models in reverse topological order *and* drop all of a module's views then tables at once (by passing multiple names to `DROP`, but for now just ignore the case where we're trying to drop an object which can't be found closes odoo/odoo#118194 Signed-off-by: Xavier Morel (xmo) --- odoo/addons/base/models/ir_model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 332cd56ea0e..ebde4fbe53c 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -287,13 +287,16 @@ class IrModel(models.Model): for model in self: current_model = self.env.get(model.model) if current_model is not None: + if current_model._abstract: + continue + table = current_model._table kind = tools.table_kind(self._cr, table) if kind == tools.TableKind.View: self._cr.execute(sql.SQL('DROP VIEW {}').format(sql.Identifier(table))) elif kind == tools.TableKind.Regular: self._cr.execute(sql.SQL('DROP TABLE {} CASCADE').format(sql.Identifier(table))) - else: + elif kind is not None: _logger.warning( "Unable to drop table %r of model %r: unmanaged or unknown tabe type %r", table, model.model, kind