-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Test suite fails with Python 3.13 due to route sorting #2012
Comments
Thanks for the report @FelixSchwarz! I haven't been able to test it yet, but as long as the result is deterministic, I don't think this is an issue. As you mention there is no real order between these paths. There are two things this sorting should achieve:
So 2 questions for you:
If so, we can add a test suite for 3.13 and change the test to just validate the two requirements I listed above instead of checking against a fixed sorting order. |
Yes.
I don't think so but this was the clearest issue for me. If I am a bit lucky, I can work on this issue over the next days/few weeks. Afterwards I'd try to clear all warnings and then proceed with Python 3.14 so we stay ahead of the curve. We already had the first rebuilds for 3.14 (alpha obviously) in Fedora which should help adapting the code of dependencies which in turn should make it easier to support 3.14 in Connexion. |
I just did a retest and actually it looks like the route sorting is the really the only issue (though two different tests fail). I am not yet sure how to adapt the test. Right now I can think of two possibilities: routes = [
"/users/{username}",
"/users/me",
"/users/{username}/items",
"/users/{username}/items/{item}",
]
sorted_routes = utils.sort_routes(routes)
assert sorted_routes.index("/users/me") < sorted_routes.index("/users/{username}")
assert sorted_routes.index("/users/{username}/items/{item}") < sorted_routes.index("/users/{username}/items")
assert sorted_routes.index("/users/{username}/items") < sorted_routes.index("/users/{username}") Or a more generic solution: import sys
expected_before_py313 = [
"/users/me",
"/users/{username}/items/{item}",
"/users/{username}/items",
"/users/{username}",
]
expected_since_py313 = [
"/users/{username}/items/{item}",
"/users/me",
"/users/{username}/items",
"/users/{username}",
]
expected = expected_before_py313 if sys.version_info < (3, 13) else expected_since_py313
assert sorted_routes == expected While the first approach encapsulates the "more specific routes first", I find it harder to understand and it might be error prone. The second approach is just more lines of code and also looks ugly. Or maybe a "hybrid" approach: routes = [
"/users/{username}",
"/users/me",
"/users/{username}/items",
"/users/{username}/items/{item}",
]
sorted_routes = utils.sort_routes(routes)
# Python 3.13 changed the sorting behavior and there is also not a real order
# between "/users/me" and "/users/{username}/items/{item}". Therefore we
# just check that /user/me is before /users/{username} (more specific routes
# need to come first) and then check the rest.
assert sorted_routes.index("/users/me") < sorted_routes.index("/users/{username}")
expected_users_username = [
"/users/{username}/items/{item}",
"/users/{username}/items",
"/users/{username}",
]
assert sorted_routes == expected_users_username I think I somehow like the last approach best because the "variable" part ( @RobbeSneyders Any opinion which approach I should follow? Any other suggestion? |
I tried to run the test suite locally using Python 3.13 but there is a test failure in
tests/test_utils.py::test_sort_routes
:I am not sure if this is actually a problem with starlette routing or just a insignificant different but I guess,
/users/me
should really be the first route.My current guess is that Python 3.13 changed its sorting behavior.
Python 3.12 calls
/users/{username}/items/{path:path} < /users/me/{path:path}
which results inFalse
so/users/me
is first in the final result.Python 3.13 does the call as well but checks
/users/me/{path:path} < /users/{username}/items/{path:path}
immediately after (returns alsoFalse
) which means there is no real order.So my questions are:
The text was updated successfully, but these errors were encountered: