fix: django async class based views#96
Conversation
|
Maybe I'm missing something but I did not care abou sync/async container. I
just tried to used wireup in an async django view
Em qui., 18 de dez. de 2025, 16:43, Aldo Mateli ***@***.***>
escreveu:
… *maldoinc* left a comment (maldoinc/wireup#96)
<#96 (comment)>
Hi, thanks for this. What kind of scenario did you run into where you're
injecting into async views but want/need a sync container instead of an
async one?
—
Reply to this email directly, view it on GitHub
<#96 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALD4R6YWP2XHWPLTXYQ5RJ34CL7W5AVCNFSM6AAAAACPNUIFDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMNZRHE2TKNZUGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
So the reason async views sort of need an async container is due to the fact that you may need to create async objects. This would fail even with the proposed change since the sync container cannot create any async objects. I think it would be good to understand what prompted django to make the Repro to cause this to err: class AsyncGreeterService:
async def agreet(self, name: str) -> str:
return f"hi {name} async"
@service
def make_async_greeter() -> AsyncGreeterService:
return AsyncGreeterService()Then have this be injected instead. |
|
Looks like to get async views to work as expected in tests you need to use the django async client. Once that's done |
|
@maldoinc pardon my stupidity I totally forgot I should use |
|
Good spot. Would be good to update the PR title, body and rebase against latest master since this is quite a bit behind. Happy to merge once that's done. Might be worth mentioning the use of async client in the docs as well as a sort of info box. |
|
Looks good. Thanks for yet another contribution! |
Fix async class-based views under ASGI
Problem
Async class-based views failed when running under an ASGI server or when tested with
AsyncClient.Changes
AsyncClientinfo box to Django docs