From 369de3fae06a8ad3b0f23ea5edb8f319447f5ac8 Mon Sep 17 00:00:00 2001 From: Camille Morand Date: Fri, 14 Aug 2026 18:29:24 +0200 Subject: [PATCH] [Fix]`endpoint_route_handler`: Restore registry._init_modules after mocked request `_get_mocked_request()` sets `registry._init_modules = set()` to simulate a minimal endpoint environment. Since registry is the real Odoo Registry singleton, this mutation persisted after the context exited. Odoo core `ir_http.py` uses `registry._init_modules` to build the routing map, so leaving it as set() caused post_install HttpCase tests from other modules to receive a routing map containing only server-wide modules, resulting in 404 errors on routes registered by those modules. Fix by saving and restoring _init_modules in a try/finally block. --- endpoint_route_handler/tests/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/endpoint_route_handler/tests/common.py b/endpoint_route_handler/tests/common.py index a0caf9bd..c2da51b9 100644 --- a/endpoint_route_handler/tests/common.py +++ b/endpoint_route_handler/tests/common.py @@ -38,6 +38,8 @@ def _setup_records(cls): def _get_mocked_request( self, env=None, httprequest=None, extra_headers=None, request_attrs=None ): + registry = (env or self.env).registry + original_init_modules = registry._init_modules with MockRequest(env or self.env) as mocked_request: mocked_request.httprequest = ( DotDict(httprequest) if httprequest else mocked_request.httprequest @@ -51,3 +53,7 @@ def _get_mocked_request( mocked_request.make_response = lambda data, **kw: data mocked_request.registry._init_modules = set() yield mocked_request + # Restore the real _init_modules. + # Without this, routing_map() keeps being built with an empty module + # set and post_install HttpCase tests in other modules get 404s. + registry._init_modules = original_init_modules