[FIX] loading: load base only once.
authorVo Minh Thu <vmt@openerp.com>
Fri, 2 Sep 2011 13:27:12 +0000 (15:27 +0200)
committerVo Minh Thu <vmt@openerp.com>
Fri, 2 Sep 2011 13:27:12 +0000 (15:27 +0200)
bzr revid: vmt@openerp.com-20110902132712-j9bgfnzbmddarr7h

openerp/modules/loading.py
openerp/modules/registry.py

index 45a466e..4bc8e44 100644 (file)
@@ -158,7 +158,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
         logger.info('module %s: loading objects', package.name)
         migrations.migrate_module(package, 'pre')
         register_module_classes(package.name)
-        models = pool.instanciate(package.name, cr)
+        models = pool.load(cr, package)
         loaded_modules.append(package.name)
         if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
             init_module_models(cr, package.name, models)
@@ -273,8 +273,6 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
         # This is a brand new pool, just created in pooler.get_db_and_pool()
         pool = pooler.get_pool(cr.dbname)
 
-        processed_modules = [] # for cleanup step after install
-        loaded_modules = [] # to avoid double loading
         report = tools.assertion_report()
         if 'base' in tools.config['update'] or 'all' in tools.config['update']:
             cr.execute("update ir_module_module set state=%s where name=%s and state=%s", ('to upgrade', 'base', 'installed'))
@@ -285,8 +283,10 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
         if not graph:
             logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module base cannot be loaded! (hint: verify addons-path)')
             raise osv.osv.except_osv(_('Could not load base module'), _('module base cannot be loaded! (hint: verify addons-path)'))
-        loaded, processed = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report)
-        processed_modules.extend(processed)
+
+        # processed_modules: for cleanup step after install
+        # loaded_modules: to avoid double loading
+        loaded_modules, processed_modules = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report)
 
         if tools.config['load_language']:
             for lang in tools.config['load_language'].split(','):
index 072082d..e88852a 100644 (file)
@@ -65,14 +65,21 @@ class Registry(object):
         """ Return a model for a given name or raise KeyError if it doesn't exist."""
         return self.models[model_name]
 
-    def instanciate(self, module, cr):
-        """ Instanciate all the classes of a given module for a particular db."""
+    def load(self, cr, module):
+        """ Load a given module in the registry.
+
+        At the Python level, the modules are already loaded, but not yet on a
+        per-registry level. This method populates a registry with the given
+        modules, i.e. it instanciates all the classes of a the given module
+        and registers them in the registry.
+
+        """
 
         res = []
 
         # Instantiate registered classes (via metamodel discovery or via explicit
         # constructor call), and add them to the pool.
-        for cls in openerp.osv.orm.MetaModel.module_to_models.get(module, []):
+        for cls in openerp.osv.orm.MetaModel.module_to_models.get(module.name, []):
             res.append(cls.createInstance(self, cr))
 
         return res