-
-
Notifications
You must be signed in to change notification settings - Fork 930
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
Remove manual contextvar copy logic #1421
Remove manual contextvar copy logic #1421
Conversation
I ran this change on anyio==3.0.0 and nothing broke. So it seems like we don't have a test for this (probably the code is covered, but not the logic). So maybe it's worth adding a quick test before merging this to be sure things work as expected? def test_accessing_context_from_threaded_sync_endpoint() -> None:
ctxvar: ContextVar[bytes] = ContextVar("ctxvar")
ctxvar.set(b"data")
def endpoint(request: Request) -> Response:
return Response(ctxvar.get())
app = Starlette(routes=[Route("/", endpoint)])
client = TestClient(app)
resp = client.get("/")
assert resp.content == b"data" |
Ooohhh.... nice bit of tidying. |
I've just noticed that this doesn't work for Python 3.6, so I can expect a pipeline failure on the following commit. EDIT: To be fair, it didn't work for Python 3.6 before... So not a relevant comment. |
…/starlette into refactor/remove-contextvars-logic
Well... That was unexpected... |
Maybe import contextvars within the test and otherwise skip the test? def test_accessing_context_from_threaded_sync_endpoint() -> None:
try:
from contextvars import ContextVar
except ImportError:
pytest.skip('test requires contextvars package to be available')
ctxvar: ContextVar[bytes] = ContextVar("ctxvar")
ctxvar.set(b"data")
def endpoint(request: Request) -> Response:
return Response(ctxvar.get())
app = Starlette(routes=[Route("/", endpoint)])
client = TestClient(app)
resp = client.get("/")
assert resp.content == b"data" |
Maybe because we require the back port on < 3.7? Line 43 in 5a5a5c3
|
That's for |
|
🤦 my bad
So I guess we're good then? The test demonstrates that things work, and we know why they work, so I don't see any issue right? |
Yep. The only "issue" is restricting anyio's possible versions. It's also important to say that anyio is working on the 4.0 release. Besides that, everything is cool. |
Since the range of anyio will be |
Awesome, thank you @Kludex ! |
anyio
3.4.0 copies the context already: agronholm/anyio#390There's no need for limiting the range just for that logic, but that's something we can clean up (now or in the future).