Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#34428 closed Bug (fixed)

ASGIStaticFilesHandler raises warning.

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, ASGIStaticFilesHandler 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 (6)

comment:1 by Carlton Gibson, 20 months ago

Has patch: set

comment:2 by Carlton Gibson, 20 months ago

Description: modified (diff)

comment:3 by Carlton Gibson, 20 months ago

Description: modified (diff)

comment:4 by Mariusz Felisiak, 20 months ago

Triage Stage: UnreviewedAccepted

comment:5 by GitHub <noreply@…>, 20 months ago

Resolution: fixed
Status: assignedclosed

In 02c356f:

Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to async iterator.

Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

In ae824ece:

[4.2.x] Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to async iterator.

Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830.
Backport of 02c356f2f3945b8075735d485c3cf48cad991011 from main

Note: See TracTickets for help on using tickets.
Back to Top