improve URL matching algorithm in case of ambiguity#2898
improve URL matching algorithm in case of ambiguity#2898AlexBrou wants to merge 4 commits intoKludex:mainfrom
Conversation
|
You have two alternative solutions here that don't involve code changes:
|
|
@alex-oleshkevich of course, reorganizing the routes was my solution for the app i was developing. even if this change is not merged, at least we should have a warning message saying "the endpoint /user/myself is unreachable due to the endpoint /user/{user_id}" . it would be helpful |
|
Closing this given the private interactions via Discord and LinkedIn. |
Summary
This is a solution for cases of ambiguity in the defined routes:
Example:
we have 2 routes:
if i make a request to /user/myself, Starlette will match it to the /user/{user_id} route because it is defined first and it results in a Full Match. However, this is ambiguous and the result would be different if the endpoints were defined in a different order by the developer.
In my opinion, it shouldn't matter the order that they are defined in, Starlette should look for the best match in case of ambiguity.
Currently, it stops looking when it finds a full match.
I suggest it keeps looking for full matches and choses the one that is stricter, which is the lowest number of Path Parameters used
Checklist