From c74528b8e3898140cbffedfc3c409a02679297b5 Mon Sep 17 00:00:00 2001 From: "Chong Wang (cwg)" Date: Thu, 30 Nov 2023 16:15:08 +0100 Subject: [PATCH] [FIX] core: avoid 'Registry' object has no attribute '_m2m' error This is because the `env.registry` may not be the latest registry in the Registries pool, which happens when new modules are installed by a request and fail. In the `setup_model` the `_m2m` is set to the old registry, but models will try to read the `_m2m` from the latest registry and raise 'Registry' object has no attribute '_m2m' error This commit fix the issue by resetting the env when necessary closes odoo/odoo#146544 X-original-commit: a433f3175a5105d9028dd9937d5461ae2d5d11fe Signed-off-by: Raphael Collet --- odoo/service/model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/odoo/service/model.py b/odoo/service/model.py index dcb6acaed92..a2d6ef40497 100644 --- a/odoo/service/model.py +++ b/odoo/service/model.py @@ -138,6 +138,7 @@ def retrying(func, env): if env.cr._closed: raise env.cr.rollback() + env.reset() env.registry.reset_changes() if request: request.session = request._get_session_and_dbname()[0] @@ -163,6 +164,7 @@ def retrying(func, env): raise RuntimeError("unreachable") except Exception: + env.reset() env.registry.reset_changes() raise