From 9f77d2e2f4b580e2fb07bc044c875dfd30008f44 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 17 Dec 2012 22:46:45 +0100 Subject: [FIX] orm,registry: properly check m2o FKs during model update + fix some models `auto_init`ed multiple times The case where no constraint existed at all was not working, and after fixing it, the ORM started to re-create the same constraints multiple times for some modules. This was for models that are split within a module (such as res.users in base, which is made of several small classes): all the partial models were going through _auto_init instead of only the final one - doing useless extra work. Unfortunately establishing the FK happens before the XML data files are loaded, so a number of FK and NOT NULL constraints failed to apply due to missing tables/records. base.sql had to be extended a bit to cover these cases in a minimalist fashion bzr revid: odo@openerp.com-20121217214645-av9n003yzterhujw --- openerp/modules/registry.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'openerp/modules') diff --git a/openerp/modules/registry.py b/openerp/modules/registry.py index afa8351bce9..23dbc280803 100644 --- a/openerp/modules/registry.py +++ b/openerp/modules/registry.py @@ -110,15 +110,16 @@ class Registry(object): and registers them in the registry. """ - - res = [] - + models_to_load = [] # need to preserve loading order # Instantiate registered classes (via the MetaModel automatic discovery # or via explicit constructor call), and add them to the pool. for cls in openerp.osv.orm.MetaModel.module_to_models.get(module.name, []): - res.append(cls.create_instance(self, cr)) - - return res + # models register themselves in self.models + model = cls.create_instance(self, cr) + if model._name not in models_to_load: + # avoid double-loading models whose declaration is split + models_to_load.append(model._name) + return [self.models[m] for m in models_to_load] def schedule_cron_jobs(self): """ Make the cron thread care about this registry/database jobs. -- cgit v1.2.3