From 38f1875e0bee72a58cb039e68d79336be1c2d963 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Tue, 24 Oct 2017 12:34:28 +0200 Subject: [PATCH] [FIX] base_action_rule: ignore uninstalled models Before this commit, creating a base_action_rule with model X from module A and then uninstalling module A would make the database crash because the algorithm would look for an uninstalled model during the Registry reinitialization. i.e. Install project and base_action_rule, create a base_action_rule depending on model project.task, try to uninstall Project -> BOOM! This is fixed by checking if the model obtained is None, in which case we log a warning (for cleanup) and skip to the next iteration (continue) opw-777301 --- addons/base_action_rule/models/base_action_rule.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/base_action_rule/models/base_action_rule.py b/addons/base_action_rule/models/base_action_rule.py index fa2df365c4c..302cba6f81c 100644 --- a/addons/base_action_rule/models/base_action_rule.py +++ b/addons/base_action_rule/models/base_action_rule.py @@ -317,7 +317,15 @@ class BaseActionRule(models.Model): # retrieve all actions, and patch their corresponding model for action_rule in self.with_context({}).search([]): - Model = self.env[action_rule.model] + Model = self.env.get(action_rule.model) + + # Do not crash if the model of the base_action_rule was uninstalled + if Model is None: + _logger.warning("Action rule with ID %d depends on model %s" % + (action_rule.id, + action_rule.model)) + continue + if action_rule.kind == 'on_create': patch(Model, 'create', make_create())