8000 🐛Fix `RuntimeError` raised when `HTTPException` has a status code with no content by iudeen · Pull Request #5365 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@iudeen
Copy link
Contributor
@iudeen iudeen commented Sep 8, 2022

Fixes/related to #4949 (comment)

Please advice if this approach is correct one.

Suggestions welcome!

@codecov
Copy link
codecov bot commented Sep 8, 2022

Codecov Report

Merging #5365 (1fe25cf) into master (6620273) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #5365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          540       540           
  Lines        13936     13951   +15     
=========================================
+ Hits         13936     13951   +15     
Impacted Files Coverage Δ
fastapi/exception_handlers.py 100.00% <100.00%> (ø)
tests/test_starlette_exception.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor
github-actions bot commented Sep 8, 2022

📝 Docs preview for commit afecf9b at: https://631a48f65533fb0233157a85--fastapi.netlify.app

@github-actions
Copy link
Contributor
github-actions bot commented Sep 8, 2022

📝 Docs preview for commit f96a078 at: https://631a4cce339597069b76e096--fastapi.netlify.app

@github-actions
Copy link
Contributor
github-actions bot commented Sep 8, 2022

📝 Docs preview for commit c357017 at: https://631a4e7d882b77006ea53e5b--fastapi.netlify.app

@iudeen iudeen changed the title fix: handle no body status codes in HTTPExceptions 🐛Fix Handle HTTPExceptions with status codes that should not support body Sep 8, 2022
@iudeen iudeen changed the title 🐛Fix Handle HTTPExceptions with status codes that should not support body 🐛Fix RuntimeError that got raised when HTTPExceptions with status codes that should not support body was raised Sep 8, 2022
Copy link
Member
@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
@iudeen
Copy link
Contributor Author
iudeen commented Sep 8, 2022

Yep, same idea as what we have in Starlette: https://github.com/encode/starlette/blob/bc61505faef15b673bf4bf65db4927daa354d6b8/starlette/middleware/exceptions.py#L99-L104

I was able to find the bug by adding debug points to ExceptionMiddleware while running the app using FastAPI and Starlette in parallel.

And thus, the code was referred from Starlette! (Sorry, should have mentioned)

@github-actions
Copy link
Contributor
github-actions bot commented Sep 8, 2022

📝 Docs preview for commit f26af44 at: https://631a5fedd66a3a17d38dcc68--fastapi.netlify.app

@github-actions
Copy link
Contributor
github-actions bot commented Sep 9, 2022 8000

📝 Docs preview for commit fda6d88 at: https://631a9d31d66a3a47438dc97b--fastapi.netlify.app

Copy link
Contributor
@JarroVGIT JarroVGIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiangolo tiangolo changed the title 🐛Fix RuntimeError that got raised when HTTPExceptions with status codes that should not support body was raised 🐛Fix RuntimeError raised when HTTPException has a status code with no content Sep 11, 2022
@tiangolo
Copy link
Member

Awesome, thanks for the fix @iudeen! 🍰 🚀

And thanks for the reviews and comments @Kludex, @JarroVGIT, @BilalAlpaslan 🙇 ☕

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.

5 participants

0