Skip to content

[16.0][IMP]fastapi: enable multi-slash routes #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 16.0
Choose a base branch
from

Conversation

PicchiSeba
Copy link
Contributor

@PicchiSeba PicchiSeba commented Apr 1, 2025

This is a Work In Progress PR, which attempts to address this issue #446.
Any suggestion is welcome

EDIT: depends on #524

@OCA-git-bot
Copy link
Contributor

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

@PicchiSeba
Copy link
Contributor Author

PicchiSeba commented Apr 30, 2025

The error seems unrelated to this PR

AttributeError: module 'marshmallow' has no attribute 'pprint'

@PicchiSeba PicchiSeba force-pushed the 16.0-fastapi-multislash-route branch from efc5e40 to 78e8805 Compare April 30, 2025 12:11
@PicchiSeba PicchiSeba marked this pull request as ready for review April 30, 2025 12:13
@PicchiSeba PicchiSeba force-pushed the 16.0-fastapi-multislash-route branch 3 times, most recently from c08daf1 to 66d4979 Compare May 5, 2025 12:59
Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

Than you for the proposal @PicchiSeba

get_uid , get_app and get_endpoint no more receive a root path. They receive a path... The parameter name should be renamed. (see also my previous comment)

@PicchiSeba PicchiSeba force-pushed the 16.0-fastapi-multislash-route branch from 66d4979 to ebe773c Compare May 14, 2025 10:32
Comment on lines 214 to 227
@tools.ormcache("path")
def get_endpoint(self, path):
# try to match the request url with the most similar endpoint
endpoints_by_length = self.search([]).sorted(
lambda fe: len(fe.root_path), reverse=True
)
endpoint = False
while endpoints_by_length:
candidate_endpoint = endpoints_by_length[0]
if path.startswith(candidate_endpoint.root_path):
endpoint = candidate_endpoint
break
endpoints_by_length -= candidate_endpoint
return endpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should handle the path as a path 😏. The use of the startswithmethod doesn't mean that your endpoint path is a sub url of the given path... e.g. /a/b is not prefix of /a/bc.

see PyTech-SRL#1

Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@lmignon
Copy link
Contributor

lmignon commented May 14, 2025

once #527 is merged, a rebase will solve the CI

@PicchiSeba PicchiSeba force-pushed the 16.0-fastapi-multislash-route branch from ebe773c to e5b9865 Compare May 15, 2025 07:18
lmignon and others added 2 commits May 15, 2025 09:32
When we lookup the fastapi.endpoint to use to process a request at a given path, we must ensure that the matching mechanism on the path and the endpoint root_path is bases on the path parts. e.g. /a/b is not prefix of /a/bc.
In the same time improves robustness of the matching mechanism and avoid useless SQL queries
[IMP] fastapi: Ensures endpoint matching is based on path parts
Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

Thank you for this great improvement @PicchiSeba

LGTM (Code review, functionnal tests)

@PicchiSeba
Copy link
Contributor Author

Thank you for this great improvement @PicchiSeba

LGTM (Code review, functionnal tests)

Thank you for your support and technical expertize!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants