[FIX] core: delay of constraints in upgrade

Sometimes, constraints are not delayed during a module upgrade: the
module is 'to upgrade' but in 'init' mode :-/
Fix this by relying on the module's state only.

closes odoo/odoo#45179

X-original-commit: 878b6538961a9b6a5fe1c6ac68d4ff39391abcdf
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
Raphael Collet
2020-02-12 11:17:54 +00:00
parent 5e01d97b1d
commit c8e79869a3
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -199,7 +199,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
models_updated |= set(model_names)
models_to_check -= set(model_names)
registry.setup_models(cr)
registry.init_models(cr, model_names, {'module': package.name}, mode)
registry.init_models(cr, model_names, {'module': package.name}, new_install)
elif package.state != 'to remove':
# The current module has simply been loaded. The models extended by this module
# and for which we updated the schema, must have their schema checked again.
+3 -3
View File
@@ -316,7 +316,7 @@ class Registry(Mapping):
try:
func(*args, **kwargs)
except Exception as e:
if self._mode == 'init':
if self._is_install:
_schema.error(*e.args)
else:
_schema.info(*e.args)
@@ -331,7 +331,7 @@ class Registry(Mapping):
except Exception as e:
_schema.error(*e.args)
def init_models(self, cr, model_names, context, mode='init'):
def init_models(self, cr, model_names, context, install=True):
""" Initialize a list of models (given by their name). Call methods
``_auto_init`` and ``init`` on each model to create or update the
database tables supporting the models.
@@ -350,7 +350,7 @@ class Registry(Mapping):
# make sure the queue does not contain some leftover from a former call
self._post_init_queue.clear()
self._mode = mode
self._is_install = install
for model in models:
model._auto_init()