Repository navigation
[18.0][IMP] endpoint_route_handler: support routes generators - #176
Conversation
Pending OCA/web-api#176 (endpoint_route_handler routes generators). To be removed once merged.
Pending OCA/web-api#176 (endpoint_route_handler routes generators). To be removed once merged.
| @@ -32,9 +32,17 @@ def _endpoint_routing_rules(self): | |||
| e_registry = self._endpoint_route_registry() | |||
| for endpoint_rule in e_registry.get_rules(): | |||
There was a problem hiding this comment.
There is no warning or error if 2 rules yield the same urls and one will silently be shadowed by the other. I think we already had this issue with handlers only.
But as that part of the code is being changed, maybe a good time to fix ?
There was a problem hiding this comment.
Agreed it's worth fixing, very important indeed, but it's pre-existing and not specific to generators:
for handlers the only guard is unique(endpoint_hash), which doesn't even hold across restarts
because the hash comes from Python's randomized hash().
This PR doesn't change the behavior for existing rules, and the only consumer of generators so far
(shopfloor) yields URLs under a unique per-app prefix, so it can't collide by construction.
I'll address it in a follow-up: detect conflicting rules (same URL, overlapping methods) when the
routing map is built, log an error w/ both owners and skip the later one, plus make endpoint_hash
stable so the DB constraint actually works.
Thanks for raising the point! ❤️
There was a problem hiding this comment.
But isn't it worth a TODO or FIXME in the code, now that we are touching that part ?
There was a problem hiding this comment.
I'm opening a PR right after this gets merged. It's something I was looking at already 😉
4278d33 to
55e6239
Compare
A rule can now provide a `generator` instead of a `handler`. The generator is called when the routing map is built and yields any number of `(url, endpoint)` pairs. This allows to register a single row for many routes computed from the code (eg: all the endpoints exposed by a set of services) without having to update the endpoint_route table every time a new route is added. Generators can be model methods (preferred, extensible via inheritance) or python classes (same lookup as handlers). A failing generator is logged and skipped so that it does not break the whole routing map. Add `utils.make_endpoint` helper to build endpoints with the routing keys required by Odoo. Based on OCA#170 (routing map w/o bound request).
55e6239 to
748dc55
Compare
|
/ocabot merge minor |
|
Hey, thanks for contributing! Proceeding to merge this for you. |
|
Congratulations, your PR was merged at e37d88c. Thanks a lot for contributing to OCA. ❤️ |
A rule can now provide a
generatorinstead of ahandler.The generator is called when the routing map is built and yields any number of
(url, endpoint).This allows to register a single
endpoint_routerow for many routes computed from the code(eg: all the endpoints exposed by a set of services), w/o having to update the table
via install hooks or migrations every time a route is added or removed.
utils.make_endpoint: build endpoints w/ the routing keys required by Odoo (type,auth,readonly, ...)drop_rules([])is a no-op (IN ()was invalid SQL)First consumer: shopfloor_base (one anchor route per app, services routes generated).