Opened 21 months ago

Last modified 21 months ago

#34428 closed Bug

ASGIStaticFilesHandler raises warning. — at Version 2

Reported by: Carlton Gibson Owned by: Carlton Gibson
Component: contrib.staticfiles Version: 4.2
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Carlton Gibson)

#33735 added async support to StreamingHttpResponse for Django 4.2.

With Django 4.2rc1 and Daphne, StreamingHttpResponse raises a warning about the incorrect iterator type being used:

http/response.py:534: Warning: StreamingHttpResponse must consume synchronous iterators in order to serve them asynchronously. Use an asynchronous iterator instead.

This is because FileResponse is not async compatible (nor is that likely, since neither is open()).

A new project with:

INSTALLED_APPS = [
    "daphne",
    ...
]

ASGI_APPLICATION = "project.asgi.application"


runserver, and then visit any page serving static files such as /admin/.

The fix is to have ASGIStaticFilesHandler adapt the iterator in the same way StreamingHttpResponse does.

Change History (2)

comment:1 by Carlton Gibson, 21 months ago

Has patch: set

comment:2 by Carlton Gibson, 21 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top