Skip to content

[18.0][IMP] endpoint_route_handler: support routes generators - #176

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
camptocamp:18-imp-endpoint_route_handler-generator
Oct 15, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:18.0from
camptocamp:18-imp-endpoint_route_handler-generator

Conversation

@simahawk

Copy link
Copy Markdown
Contributor

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).

This allows to register a single endpoint_route row 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.

  • generators can be model methods (preferred: extensible via inheritance) or python classes (same lookup as handlers)
  • a failing generator is logged and skipped: it does not break the whole routing map
  • 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).

@OCA-git-bot OCA-git-bot added series:18.0 mod:endpoint_route_handler Module endpoint_route_handler labels Oct 10, 2026
simahawk added a commit to camptocamp/shopfloor-app that referenced this pull request Oct 10, 2026
Pending OCA/web-api#176 (endpoint_route_handler routes generators).
To be removed once merged.
simahawk added a commit to camptocamp/shopfloor-app that referenced this pull request Oct 10, 2026
Pending OCA/web-api#176 (endpoint_route_handler routes generators).
To be removed once merged.
@simahawk
simahawk marked this pull request as ready for review October 10, 2026 14:51
@@ -32,9 +32,17 @@ def _endpoint_routing_rules(self):
e_registry = self._endpoint_route_registry()
for endpoint_rule in e_registry.get_rules():

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.

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 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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! ❤️

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.

But isn't it worth a TODO or FIXME in the code, now that we are touching that part ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm opening a PR right after this gets merged. It's something I was looking at already 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FTR #178

@simahawk
simahawk force-pushed the 18-imp-endpoint_route_handler-generator branch from 4278d33 to 55e6239 Compare October 15, 2026 07:38
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).
@simahawk
simahawk force-pushed the 18-imp-endpoint_route_handler-generator branch from 55e6239 to 748dc55 Compare October 15, 2026 11:15
@simahawk

Copy link
Copy Markdown
Contributor Author

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 18.0-ocabot-merge-pr-176-by-simahawk-bump-minor, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit a5ca282 into OCA:18.0 Oct 15, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at e37d88c. 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.

3 participants