From 32f51689742cdec79ad2bc41ac37bb53fbb6f199 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 15 Sep 2014 15:24:43 +0200 Subject: [PATCH] [FIX] orm: do not drop foreign keys of transient models During the update of a module, the existing foreign keys are dropped if they have a different ondelete_rule than the one specified on the field. The foreign keys for many2one transiant -> non-transiant are created with cascade rule by default (see `m2o_add_foreign_key_checked` method) so the check needs to be realised in the same conditions. --- openerp/osv/orm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 9bf10df39d6..07ed496000c 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3016,6 +3016,9 @@ class BaseModel(object): if len(constraints) == 1: # Is it the right constraint? cons, = constraints + if self.is_transient() and not dest_model.is_transient(): + # transient foreign keys are added as cascade by default + ondelete = ondelete or 'cascade' if cons['ondelete_rule'] != POSTGRES_CONFDELTYPES.get((ondelete or 'set null').upper(), 'a')\ or cons['foreign_table'] != dest_model._table: # Wrong FK: drop it and recreate