Skip to content
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

Sort routes in RoutingMiddleware #1898

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kosciCZ
Copy link

@kosciCZ kosciCZ commented Mar 18, 2024

Fixes #1879

Please let me know if this is the correct place to perform the sort or if any more changes are needed.

I've ran into this issue while migrating a large API from connexion 2 to connexion 3 (Async app variant) and the changes implemented here fixed route mismatching.

@RobbeSneyders
Copy link
Member

Thanks @kosciCZ, I think we need to update this in the AbstractRoutingMiddleware though.

@RobbeSneyders
Copy link
Member

Hi @kosciCZ, do you have time to have another look at this?

@kosciCZ
Copy link
Author

kosciCZ commented Apr 15, 2024

@RobbeSneyders sorry about that, yes, definitely. Could you throw me some pointers on the general outline of the solution?

My idea with this was that this is mostly Starlette specific, since their route matching iterates over routes and performs regex matches until a match is found, so order is important. With Flask, this does not seem to be an issue (our API on sync connexion 2.x matched routes correctly without having to sort them). So, that's why I chose to sort them all after the routes have been mounted, as that seemed like the appropriate place. Would you like me to replicate that in the method you referenced?

@kosciCZ
Copy link
Author

kosciCZ commented May 6, 2024

@RobbeSneyders any thoughts on ^?

@RobbeSneyders
Copy link
Member

Hi @kosciCZ, I would prefer to update it in the AbstractRoutingMiddleware, so the behavior is consistent across all places where we are routing requests, even if the resulting behavior is the same.

@coveralls
Copy link

Coverage Status

coverage: 94.2% (+0.003%) from 94.197%
when pulling 93c4a1e on kosciCZ:sort-routes-middleware
into 160a1c0 on spec-first:main.

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.

RoutingMiddleware should sort paths
3 participants