[Django] #34428: ASGIStaticFilesHandler raises warning.

219 views
Skip to first unread message

Django

unread,
Mar 21, 2023, 11:31:07 AM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton | Owner: Carlton Gibson
Gibson |
Type: Bug | Status: assigned
Component: | Version: 4.2
contrib.staticfiles |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
#33735 added async support to StreamingHttpResponse for Django 4.2.

With Django 4.2rc1 and Daphne, ``` 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34428>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 21, 2023, 11:32:47 AM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton

| Gibson
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16670 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:1>

Django

unread,
Mar 21, 2023, 12:03:42 PM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Carlton Gibson:

Old description:

> #33735 added async support to StreamingHttpResponse for Django 4.2.
>
> With Django 4.2rc1 and Daphne, ``` 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.

New description:

#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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:2>

Django

unread,
Mar 21, 2023, 12:25:41 PM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Carlton Gibson:

Old description:

> #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.

New description:

#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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:3>

Django

unread,
Mar 21, 2023, 2:33:48 PM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:4>

Django

unread,
Mar 21, 2023, 3:52:07 PM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
| Gibson
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"02c356f2f3945b8075735d485c3cf48cad991011" 02c356f]:
{{{
#!CommitTicketReference repository=""
revision="02c356f2f3945b8075735d485c3cf48cad991011"
Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to async
iterator.

Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:5>

Django

unread,
Mar 21, 2023, 3:53:29 PM3/21/23
to django-...@googlegroups.com
#34428: ASGIStaticFilesHandler raises warning.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
| Gibson
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"ae824eceb1ddcaef336677bf9a6e704097cd2309" ae824ece]:
{{{
#!CommitTicketReference repository=""
revision="ae824eceb1ddcaef336677bf9a6e704097cd2309"
[4.2.x] Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to
async iterator.

Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830.
Backport of 02c356f2f3945b8075735d485c3cf48cad991011 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34428#comment:6>

Reply all
Reply to author
Forward
0 new messages