[FIX] endpoint_route_handler: build routing map without a bound request - #159
Open
omar-d1 wants to merge 1 commit into
Open
[FIX] endpoint_route_handler: build routing map without a bound request#159omar-d1 wants to merge 1 commit into
omar-d1 wants to merge 1 commit into
Conversation
Contributor
|
Hi @simahawk, |
routing_map() is wrapped with an ormcache whose key calls _endpoint_route_last_version(), and the routing rules are injected by _endpoint_routing_rules(). Both are classmethods, so neither has self.env and both reach the endpoint registry through http.request.env. Off a request that proxy is unbound and raises "RuntimeError: object is not bound". Odoo 19 calls routing_map() that way: website.technical.page builds its SQL view from get_static_routes(), which walks the map, and website's TestWebsiteTechnicalPage exercises it from a TransactionCase. Crons and `odoo shell` hit the same wall. The existing tests never caught it because they all wrap their calls in MockRequest. routing_map() is a model method, so self.env already holds a cursor and the request was never needed. Make both helpers instance methods reading self.env. They are only called as self.<method>() from this module, and the tests already call _endpoint_route_last_version() on a recordset, so no call site changes. last_version() reads a sequence, so any cursor on the database returns the same value and the cache key is unchanged. Add a regression test that builds the map with no request bound.
omar-d1
force-pushed
the
19.0-fix-routing-map-unbound-request
branch
from
August 26, 2026 12:29
1487ea5 to
9cb75ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
routing_map()raisesRuntimeError: object is not boundwhenever it is called with no HTTP request in flight.Both helpers this module adds to
ir.httpare classmethods, so neither hasself.env, and both reach the endpoint registry throughhttp.request.env:The second one sits in the ormcache key of
routing_map, so it runs before the wrapped body and the failure happens while computing the key.How to reproduce
One line in
odoo shell, on a database withendpoint_route_handlerinstalled:Odoo 19 reaches it through core too.
website.technical.pagebuilds its SQL view fromget_static_routes(), which walks the routing map, andwebsite'sTestWebsiteTechnicalPageexercises that from aTransactionCase. On a database with this module installed,website_hr_recruitment'sTestWebsiteHrRecruitmentTechnicalPageerrors out. Crons and shell scripts hit the same wall.The existing tests never caught it because they all wrap their calls in
MockRequest, so a request was always present.Fix
routing_map()is a model method, soself.envalready holds a cursor. The request was never needed. Both helpers become instance methods readingself.env.They are only ever called as
self.<method>()from this module, and the tests already call_endpoint_route_last_version()on a recordset, so no call site changes.last_version()reads a sequence, so any cursor on the database returns the same value and the cache key is unchanged.TestEndpointCrossEnvstill passes: I checked two separate envs and both report the same version.Test
Added a regression test that builds the map with no request bound.