ASGI zipfly on Django 4.2 first packages the file(s) to memory, then sends to client
Opened this issue · 2 comments
I've tried multiple times to make this work but I've ran out of options. So this is more like a cry for help.
Kinda sucks, since the same application this happens on, would benefit from having websockets enabled.
Without seeing the code, I really couldn't tell you what the problem is.
Having said that, the easy solution is to separate the downloads from the app itself.
The same code works on both WSGI and ASGI, and it produces the zipfile as expected. The only difference is that in ASGI mode it first creates the zipfile in memory and then sends it to client.
Tried fooling around with this today. It seems to boil down to Django's StreamingHttpResponse not accepting synchronous iterators when in ASGI mode. It throws this warning:
/usr/local/lib/python3.11/site-packages/django/http/response.py:534: Warning: StreamingHttpResponse must consume synchronous iterators in order to serve them asynchronously. Use an asynchronous iterator instead.
Spent a few hours trying to splash async/await and @sync_to_async decorators all around the code, but alas; no success yet.