[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) <xmo@odoo.com>
This commit is contained in:
Xavier Morel
2023-04-11 15:17:32 +02:00
parent baebb6a5b0
commit cedc968f22
+4 -1
View File
@@ -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