Fix middleware traceback fetching on Python 3.8+, fix ResourceWarnings in TestClient, fix CI build#1132
Merged
florimondmanca merged 3 commits intomasterfrom Jan 31, 2021
Merged
Conversation
euri10
approved these changes
Jan 31, 2021
Contributor
euri10
left a comment
There was a problem hiding this comment.
Something in a dependency (pytest? Python itself?)
It's pytest itself (since 6.2 https://docs.pytest.org/en/stable/usage.html#unraisable) and if you look it happens only on 3.8 and above as expected.
Since we turn warnings into exceptions then this popped off.
Uvicorn has a pending PR to do the same.
florimondmanca
approved these changes
Jan 31, 2021
Contributor
florimondmanca
left a comment
There was a problem hiding this comment.
Thanks so much ❤️
Contributor
|
@JayH5 I updated the title bc there are 2 items we'll want this PR to be included in the changelog for (fixing tracebacks, fixing |
Contributor
|
Depending on what's currently in |
Contributor
Author
|
Thanks @euri10 @florimondmanca ❤️ I'll look at doing a release soon. |
Merged
10 tasks
mweinelt
added a commit
to mweinelt/nixpkgs
that referenced
this pull request
Mar 20, 2021
- ujson was dropped in Kludex/starlette#1047 - test_debug_html was fixed in Kludex/starlette#1132
risicle
added a commit
to risicle/nixpkgs
that referenced
this pull request
Jun 1, 2021
newer python 3.8+ releases expose this breakage Kludex/starlette#1131, fixed upstream in Kludex/starlette#1132
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This would ideally be 3 separate PRs, but all of these issues have broken the build on master so it'd be difficult to demonstrate them working separately. Still, let me know if you'd like me to split things up.
The issues are:
tests/middleware/*to have type annotations, despite this being disabled fortestssubmodules. Mypy was not correctly identifying that these tests were submodules due to the lack of an__init__.pyfile. See somebody having a similar problem in mypy.ini module-specific override doesn't work without__init__.pypython/mypy#9974. An alternative (or something we could also do) would be to addnamespace_packages = Trueto the config. Since we have__init__.pyfiles everywhere else, I went with that option for now.ResourceWarnings detected due to unclosed sockets. These (Unix) sockets I believe were setup by the asyncio event loop as part of its internal machinery. In theTestClient, in theWebSocketTestSessionwe weren't closing the event loop used by the worker thread there. I changed the loop creation to be done inside the thread (since it is only used by the thread, and can never be used again once the thread has completed) and closed the loop at the end of its use (also in the thread). Possibly fixes fix Unraisable ResourceWarnings #1050ServerErrorMiddlewarewe were using the undocumentedexc_tracebackattribute ofTracebackError. This attribute was removed for bpo42482 in Python 3.9.1 & 3.8.7. I switched to using the__traceback__attribute of exceptions which I think should have the same value (it at least produces the same HTML for the test case we have). I also added a check that the exception actually had a traceback, which we weren't doing previously but probably should've been. Fixes Test failure #1131, The debug mode does not work well #1126