Skip to content

[19.0][IMP] endpoint_route_handler: restore _init_modules even when a test raises - #166

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
qrtl:19.0-fix-endpoint_route_handler-init-modules
Sep 16, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:19.0from
qrtl:19.0-fix-endpoint_route_handler-init-modules

Conversation

@AungKoKoLin1997

@AungKoKoLin1997 AungKoKoLin1997 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Follow-up to 369de3f, which restores registry._init_modules after _get_mocked_request but does the restore after the with MockRequest(...) block, without a try/finally. If the test body raises inside the mocked request, the exception propagates out of the generator and the restore line is never reached, so the process-wide registry is left with an empty module set again.

That attribute is not rolled back with the test transaction, and ir.http.routing_map() builds the routing map from exactly that set:

installed = registry._init_modules.union(config["server_wide_modules"])

so the next routing-map regeneration yields no module controllers at all, and every later HttpCase in the same process gets a 404 for any route outside base — the very failure 369de3f set out to fix, just on the error path.

This PR wraps the yield in try/finally so the restore always runs.

🤖 Generated with Claude Code

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:19.0 mod:endpoint_route_handler Module endpoint_route_handler labels Sep 16, 2026
@yostashiro

Copy link
Copy Markdown
Member

@AungKoKoLin1997 Please rebase. I guess it supplements #150 which was just merged.

…raises

369de3f restores `registry._init_modules` after `_get_mocked_request`, but the
restore happens after the `with MockRequest(...)` block without a `try/finally`.
If the test body raises inside the mocked request, the exception propagates out
of the generator and the restore line is never reached, so the process-wide
registry is left with an empty module set again.

That attribute is not rolled back with the test transaction, and
`ir.http.routing_map()` builds the routing map from exactly that set:

    installed = registry._init_modules.union(config["server_wide_modules"])

so the next routing-map regeneration yields no module controllers at all and
every later `HttpCase` in the same process gets a 404 for any route outside
`base` - the very failure 369de3f set out to fix, just on the error path.

Wrap the `yield` in `try/finally` so the restore always runs.

Assisted-by: Claude Opus 5
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-fix-endpoint_route_handler-init-modules branch from c57237c to 6fc2084 Compare September 16, 2026 07:48
@AungKoKoLin1997 AungKoKoLin1997 changed the title [19.0][FIX] endpoint_route_handler: restore registry._init_modules after a mocked request [19.0][IMP] endpoint_route_handler: restore _init_modules even when a test raises Sep 16, 2026
AungKoKoLin1997 added a commit to qrtl/ocj-oca that referenced this pull request Sep 16, 2026
…ter a mocked request

`CommonEndpoint._get_mocked_request` empties `registry._init_modules` and never
puts it back. That attribute lives on the process-wide registry, so it is not
rolled back with the test transaction, and `ir.http.routing_map()` builds the
map from exactly that set:

    installed = registry._init_modules.union(config['server_wide_modules'])

Once the endpoint tests have run, the next routing-map regeneration therefore
yields no module controllers at all, and every later `HttpCase` in the same
process gets a 404 for any route outside `base`. The endpoint suite itself
never noticed because nothing after it made an HTTP request.

Adding `queue_job` to this repository surfaced it: its post-install
`TestRunJobHttp` calls `/queue_job/runjob` and got 404 in CI while passing in
isolation. Restoring the previous value on exit fixes both those tests and
leaves the endpoint suite unchanged.

Upstream has since merged the same fix (OCA/web-api 369de3f), plus the pending
OCA/web-api#166 which moves the restore into a `try/finally` so it also runs
when a test raises inside the mocked request. This patch is that combined
state, so the next re-vendoring of the module is a no-op here.

Assisted-by: Claude Opus 5
yostashiro pushed a commit to qrtl/ocj-oca that referenced this pull request Sep 16, 2026
…ter a mocked request (#43)

`CommonEndpoint._get_mocked_request` empties `registry._init_modules` and never
puts it back. That attribute lives on the process-wide registry, so it is not
rolled back with the test transaction, and `ir.http.routing_map()` builds the
map from exactly that set:

    installed = registry._init_modules.union(config['server_wide_modules'])

Once the endpoint tests have run, the next routing-map regeneration therefore
yields no module controllers at all, and every later `HttpCase` in the same
process gets a 404 for any route outside `base`. The endpoint suite itself
never noticed because nothing after it made an HTTP request.

Adding `queue_job` to this repository surfaced it: its post-install
`TestRunJobHttp` calls `/queue_job/runjob` and got 404 in CI while passing in
isolation. Restoring the previous value on exit fixes both those tests and
leaves the endpoint suite unchanged.

Upstream has since merged the same fix (OCA/web-api 369de3f), plus the pending
OCA/web-api#166 which moves the restore into a `try/finally` so it also runs
when a test raises inside the mocked request. This patch is that combined
state, so the next re-vendoring of the module is a no-op here.

Assisted-by: Claude Opus 5

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@simahawk

Copy link
Copy Markdown
Contributor

/ocabot merge patch
Would you mind porting the whole fix to 18?

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 19.0-ocabot-merge-pr-166-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit a5bb5e5 into OCA:19.0 Sep 16, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 6942a5e. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants