Skip to content
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

ASGI zipfly on Django 4.2 first packages the file(s) to memory, then sends to client #100

Open
T-101 opened this issue Apr 21, 2023 · 2 comments

Comments

@T-101
Copy link

T-101 commented Apr 21, 2023

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.

@T-101 T-101 changed the title ASGI zipfly on Django 4.2 first packages to file(s) to memory, then sends to client ASGI zipfly on Django 4.2 first packages the file(s) to memory, then sends to client Apr 21, 2023
@sandes
Copy link
Owner

sandes commented Apr 22, 2023

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.

@T-101
Copy link
Author

T-101 commented Apr 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants