[FIX] base/ir_model: fix materialized views columns listing
When there is a materialized view that has not been populated any select
on it will fail.
Example of traceback:
```
Traceback (most recent call last):
File "/home/odoo/src/odoo/12.0/odoo/service/server.py", line 1162, in preload_registries
registry = Registry.new(dbname, update_module=update_module)
File "/home/odoo/src/odoo/12.0/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/odoo/src/odoo/12.0/odoo/modules/loading.py", line 367, in load_modules
registry.setup_models(cr)
File "/home/odoo/src/odoo/12.0/odoo/modules/registry.py", line 262, in setup_models
env['ir.model']._add_manual_models()
File "/home/odoo/src/odoo/12.0/odoo/addons/base/models/ir_model.py", line 321, in _add_manual_models
cr.execute('SELECT * FROM %s LIMIT 0' % Model._table)
File "/home/odoo/src/odoo/12.0/odoo/sql_db.py", line 148, in wrapper
return f(self, *args, **kwargs)
File "/home/odoo/src/odoo/12.0/odoo/sql_db.py", line 225, in execute
res = self._obj.execute(query, params)
psycopg2.errors.ObjectNotInPrerequisiteState: materialized view "x_bi_sql_view_report_copy" has not been populated
HINT: Use the REFRESH MATERIALIZED VIEW command.
```
Several upgrade requests have or had had this error which has been
solved with specific scripts.
Related to #40930
closes odoo/odoo#71008
X-original-commit: b208570ce8399bc6d3e4a8ba02eef6558e0a6ccc
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -429,8 +429,18 @@ class IrModel(models.Model):
|
||||
if tools.table_kind(cr, Model._table) not in ('r', None):
|
||||
# not a regular table, so disable schema upgrades
|
||||
Model._auto = False
|
||||
cr.execute('SELECT * FROM %s LIMIT 0' % Model._table)
|
||||
columns = {desc[0] for desc in cr.description}
|
||||
cr.execute(
|
||||
'''
|
||||
SELECT a.attname
|
||||
FROM pg_attribute a
|
||||
JOIN pg_class t
|
||||
ON a.attrelid = t.oid
|
||||
AND t.relname = %s
|
||||
WHERE a.attnum > 0 -- skip system columns
|
||||
''',
|
||||
[Model._table]
|
||||
)
|
||||
columns = {colinfo[0] for colinfo in cr.fetchall()}
|
||||
Model._log_access = set(models.LOG_ACCESS_COLUMNS) <= columns
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user