From ae000f07e17c69652f2fd243650bbf976e1b9a4d Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 26 Apr 2023 12:28:06 +0000 Subject: [PATCH] [FIX] loading: check ir_module existence When instantiating a new registry, this piece of code is called try: odoo.modules.load_modules(registry, force_demo, status, update_module) except Exception: odoo.modules.reset_modules_state(db_name) raise For a new database, load_modules will create the table ir_module_module in the same transaction as everything else. This means that if any error occurs, the transaction is rollbacked and the table ir_module may not exist. `reset_modules_state` will try to access ir_module_module table leading to another error and an unecessary and confusing error log. 2023-04-26 12:05:34,823 616958 ERROR ? odoo.sql_db: bad query: UPDATE ir_module_module SET state='installed' WHERE state IN ('to remove', 'to upgrade') ERROR: relation "ir_module_module" does not exist LINE 1: UPDATE ir_module_module SET state='installed' WHERE state IN... ^ 2023-04-26 12:05:34,823 616958 ERROR ? odoo.modules.registry: Failed to load registry 2023-04-26 12:05:34,824 616958 CRITICAL ? odoo.service.server: Failed to initialize database `test-base`. Traceback (most recent call last): File "/home/xdo/osrc/master/odoo/odoo/modules/registry.py", line 90, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/home/xdo/osrc/master/odoo/odoo/modules/loading.py", line 386, in load_modules raise Exception('An error') Exception: An error During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xdo/osrc/master/odoo/odoo/service/server.py", line 1302, in preload_registries registry = Registry.new(dbname, update_module=update_module) File "", line 2, in new File "/home/xdo/osrc/master/odoo/odoo/tools/func.py", line 87, in locked return func(inst, *args, **kwargs) File "/home/xdo/osrc/master/odoo/odoo/modules/registry.py", line 92, in new odoo.modules.reset_modules_state(db_name) File "/home/xdo/osrc/master/odoo/odoo/modules/loading.py", line 622, in reset_modules_state cr.execute( File "/home/xdo/osrc/master/odoo/odoo/sql_db.py", line 311, in execute res = self._obj.execute(query, params) psycopg2.errors.UndefinedTable: relation "ir_module_module" does not exist LINE 1: UPDATE ir_module_module SET state='installed' WHERE state IN... With this commit, we check the ir_module_module table existance avoiding an exception and revealing the minimal traceback. 2023-04-26 12:11:21,218 617810 INFO ? odoo.modules.loading: skipping reset_modules_state, ir_module_module table does not exists 2023-04-26 12:11:21,218 617810 ERROR ? odoo.modules.registry: Failed to load registry 2023-04-26 12:11:21,218 617810 CRITICAL ? odoo.service.server: Failed to initialize database `test-base`. Traceback (most recent call last): File "/home/xdo/osrc/master/odoo/odoo/service/server.py", line 1302, in preload_registries registry = Registry.new(dbname, update_module=update_module) File "", line 2, in new File "/home/xdo/osrc/master/odoo/odoo/tools/func.py", line 87, in locked return func(inst, *args, **kwargs) File "/home/xdo/osrc/master/odoo/odoo/modules/registry.py", line 90, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/home/xdo/osrc/master/odoo/odoo/modules/loading.py", line 386, in load_modules raise Exception('An error') closes odoo/odoo#119820 Exception: An error Signed-off-by: Raphael Collet --- odoo/modules/loading.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py index bda9f35fab9..18faa38ac9b 100644 --- a/odoo/modules/loading.py +++ b/odoo/modules/loading.py @@ -619,6 +619,10 @@ def reset_modules_state(db_name): # of time db = odoo.sql_db.db_connect(db_name) with db.cursor() as cr: + cr.execute("SELECT 1 FROM information_schema.tables WHERE table_name='ir_module_module'") + if not cr.fetchall(): + _logger.info('skipping reset_modules_state, ir_module_module table does not exists') + return cr.execute( "UPDATE ir_module_module SET state='installed' WHERE state IN ('to remove', 'to upgrade')" )