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 methods to stabalize operation id generation #5001
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5001 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 540 532 -8
Lines 13969 13672 -297
==========================================
- Hits 13969 13672 -297 ☔ View full report in Codecov by Sentry. |
📝 Docs preview for commit 6379d7b at: https://62a06605ac380a00565f275f--fastapi.netlify.app |
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 would work and indeed solves a minor bug. You haven't supplied a test case for this though, might help in getting this PR approved by Tiangolo
Because it's runtime random behavior, I find it hard to come up with a proper test case that will work across different python versions and will make sure we are actually doing the right thing instead of possibly passing because of shear luck. Consider the following output: Python 3.8.9 (default, Dec 16 2021, 12:39:57)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information
>>> b=set(["2","1","3"])
>>> list(b)[0]
'1'
>>> b=set(["1","2","3"])
>>> list(b)[0]
'3'
>>> b=set(["1","2","3"])
>>> list(b)[0]
'3'
>>> b=set(["1","2","3"])
>>> list(b)[0]
'3'
>>> b=set(["1","2","3"])
>>> list(b)[0]
'3'
>>> b=set(["1","2","4"])
>>> list(b)[0]
'4' |
Yeah I was having a stroll outside right after I made that comment, and I had the exact same thought. You are right, I also couldn't find a way to properly test it. That leaves me with the thought that somehow (if not through a specific test case) we would want to make it specific that there was a reason this line of code uses
Let me know your thoughts! |
The methods attribute accessed by the `generate_unique_id` function is modeled as a python set, which is not ordered and between runs might change. This results in the same fastapi generating different openapi specs if started multiple times. This also relates to the bigger issue tiangolo#4740 but is not a solution for that issue.
I've decided to add a comment. I was writing the test case and came to the conclusion that there would be no way to write the test that would still make sense if APIRoute would be refactored to accept a single http method only. Because I think that will probably end up being the outcome of #4740 I decided a comment would be best for now. Happy to hear from official reviewers on this. |
📝 Docs preview for commit ea7b56d at: https://62a3a49a1ffcb30a6f50af62--fastapi.netlify.app |
The methods attribute accessed by the
generate_unique_id
function is modeled as a python set, which is not ordered and between runs might change. This results in the same fastapi generating different openapi specs if started multiple times.This also relates to the bigger issue #4740 but is not a solution for that issue.