-
-
Notifications
You must be signed in to change notification settings - Fork 329
[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
base: 16.0
Are you sure you want to change the base?
Conversation
Hi @lmignon, |
e2a6cce
to
f7dda08
Compare
f7dda08
to
efc5e40
Compare
The error seems unrelated to this PR
|
efc5e40
to
78e8805
Compare
c08daf1
to
66d4979
Compare
There was a problem hiding this 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)
66d4979
to
ebe773c
Compare
fastapi/models/fastapi_endpoint.py
Outdated
@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 |
There was a problem hiding this comment.
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 startswith
method 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see PyTech-SRL#1
once #527 is merged, a rebase will solve the CI |
ebe773c
to
e5b9865
Compare
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
There was a problem hiding this 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)
Thank you for your support and technical expertize! |
This is a Work In Progress PR, which attempts to address this issue #446.
Any suggestion is welcome
EDIT: depends on #524