-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
Fix middleware traceback fetching on Python 3.8+, fix ResourceWarnings in TestClient, fix CI build #1132
Conversation
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.
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.
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.
Thanks so much ❤️
@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 |
Depending on what's currently in |
Thanks @euri10 @florimondmanca ❤️ I'll look at doing a release soon. |
- ujson was dropped in encode/starlette#1047 - test_debug_html was fixed in encode/starlette#1132
newer python 3.8+ releases expose this breakage encode/starlette#1131, fixed upstream in encode/starlette#1132
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 fortests
submodules. Mypy was not correctly identifying that these tests were submodules due to the lack of an__init__.py
file. See somebody having a similar problem in mypy.ini module-specific override doesn't work without__init__.py
python/mypy#9974. An alternative (or something we could also do) would be to addnamespace_packages = True
to the config. Since we have__init__.py
files everywhere else, I went with that option for now.ResourceWarning
s 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 theWebSocketTestSession
we 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 #1050ServerErrorMiddleware
we were using the undocumentedexc_traceback
attribute 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