[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 <rco@odoo.com>
This commit is contained in:
Chong Wang (cwg)
2023-12-15 21:02:10 +00:00
parent a7f2056b15
commit c74528b8e3
+2
View File
@@ -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