Skip to content

Commit 369de3f

Browse files
committed
[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.
1 parent 2d8217b commit 369de3f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

endpoint_route_handler/tests/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def _setup_records(cls):
3838
def _get_mocked_request(
3939
self, env=None, httprequest=None, extra_headers=None, request_attrs=None
4040
):
41+
registry = (env or self.env).registry
42+
original_init_modules = registry._init_modules
4143
with MockRequest(env or self.env) as mocked_request:
4244
mocked_request.httprequest = (
4345
DotDict(httprequest) if httprequest else mocked_request.httprequest
@@ -51,3 +53,7 @@ def _get_mocked_request(
5153
mocked_request.make_response = lambda data, **kw: data
5254
mocked_request.registry._init_modules = set()
5355
yield mocked_request
56+
# Restore the real _init_modules.
57+
# Without this, routing_map() keeps being built with an empty module
58+
# set and post_install HttpCase tests in other modules get 404s.
59+
registry._init_modules = original_init_modules

0 commit comments

Comments
 (0)