[Django] #33716: Async-capable middleware is not async-capable

13 views
Skip to first unread message

Django

unread,
May 17, 2022, 6:15:24 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
-------------------------------------------+------------------------
Reporter: abetkin | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
All the standard django middleware is marked as async-capable. As I
understand that means that sync_to_async adapters will not be used if no
other middleware is present.

However, if you call an endpoint that is handled by an async view, somehow
the adapters are still used, and middleware is executed in a separate
thread.

Moreover, if you add your custom middleware that is async_capable than it
tries not to use adapters, and quickly fails:

{{{
AttributeError: 'coroutine' object has no attribute 'get'
}}}

In this example this was XFrameOptionsMiddleware that failed

Github project illustrating this: https://github.com/pwtail/django_bug

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

Django

unread,
May 17, 2022, 6:16:32 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
---------------------------------+--------------------------------------

Reporter: abetkin | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Release blocker | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by abetkin):

* Attachment "bug.png" added.

Django

unread,
May 17, 2022, 6:17:32 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
---------------------------------+--------------------------------------
Reporter: abetkin | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by abetkin:

Old description:

> All the standard django middleware is marked as async-capable. As I
> understand that means that sync_to_async adapters will not be used if no
> other middleware is present.
>
> However, if you call an endpoint that is handled by an async view,
> somehow the adapters are still used, and middleware is executed in a
> separate thread.
>
> Moreover, if you add your custom middleware that is async_capable than it
> tries not to use adapters, and quickly fails:
>
> {{{
> AttributeError: 'coroutine' object has no attribute 'get'
> }}}
>
> In this example this was XFrameOptionsMiddleware that failed
>
> Github project illustrating this: https://github.com/pwtail/django_bug

New description:

All the standard django middleware is marked as async-capable. As I
understand that means that sync_to_async adapters will not be used if no
other middleware is present.

However, if you call an endpoint that is handled by an async view, somehow
the adapters are still used, and middleware is executed in a separate
thread.

Moreover, if you add your custom middleware that is async_capable than it
tries not to use adapters, and quickly fails:

[[Image(https://code.djangoproject.com/attachment/ticket/33716/bug.png)]]

{{{
AttributeError: 'coroutine' object has no attribute 'get'
}}}

In this example this was XFrameOptionsMiddleware that failed

Github project illustrating this: https://github.com/pwtail/django_bug

--

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

Django

unread,
May 17, 2022, 6:20:38 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
---------------------------------+--------------------------------------
Reporter: abetkin | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by abetkin:

Old description:

> All the standard django middleware is marked as async-capable. As I
> understand that means that sync_to_async adapters will not be used if no
> other middleware is present.
>
> However, if you call an endpoint that is handled by an async view,
> somehow the adapters are still used, and middleware is executed in a
> separate thread.
>
> Moreover, if you add your custom middleware that is async_capable than it
> tries not to use adapters, and quickly fails:
>

> [[Image(https://code.djangoproject.com/attachment/ticket/33716/bug.png)]]
>
> {{{
> AttributeError: 'coroutine' object has no attribute 'get'
> }}}
>
> In this example this was XFrameOptionsMiddleware that failed
>
> Github project illustrating this: https://github.com/pwtail/django_bug

New description:

All the standard django middleware is marked as async-capable. As I
understand that means that sync_to_async adapters will not be used if no
other middleware is present.

However, if you call an endpoint that is handled by an async view, somehow
the adapters are still used, and middleware is executed in a separate
thread.

Moreover, if you add your custom middleware that is async_capable than it
tries not to use adapters, and quickly fails:

[[https://code.djangoproject.com/attachment/ticket/33716/bug.png]]

{{{
AttributeError: 'coroutine' object has no attribute 'get'
}}}

In this example this was XFrameOptionsMiddleware that failed

Github project illustrating this: https://github.com/pwtail/django_bug

--

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

Django

unread,
May 17, 2022, 6:22:04 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
---------------------------------+------------------------------------
Reporter: abetkin | Owner: nobody
Type: Bug | Status: new

Component: Uncategorized | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

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

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Old description:

> All the standard django middleware is marked as async-capable. As I
> understand that means that sync_to_async adapters will not be used if no
> other middleware is present.
>
> However, if you call an endpoint that is handled by an async view,
> somehow the adapters are still used, and middleware is executed in a
> separate thread.
>
> Moreover, if you add your custom middleware that is async_capable than it
> tries not to use adapters, and quickly fails:
>

> [[https://code.djangoproject.com/attachment/ticket/33716/bug.png]]
>
> {{{
> AttributeError: 'coroutine' object has no attribute 'get'
> }}}
>
> In this example this was XFrameOptionsMiddleware that failed
>
> Github project illustrating this: https://github.com/pwtail/django_bug

New description:

All the standard django middleware is marked as async-capable. As I
understand that means that sync_to_async adapters will not be used if no
other middleware is present.

However, if you call an endpoint that is handled by an async view, somehow
the adapters are still used, and middleware is executed in a separate
thread.

Moreover, if you add your custom middleware that is async_capable than it
tries not to use adapters, and quickly fails:

[[https://code.djangoproject.com/attachment/ticket/33716/bug.png]]

{{{
AttributeError: 'coroutine' object has no attribute 'get'
}}}

In this example this was XFrameOptionsMiddleware that failed

Github project illustrating this: https://github.com/pwtail/django_bug

Is reproduced in thae main branch and in 4.0

--

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

Django

unread,
May 17, 2022, 7:09:07 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
---------------------------------+------------------------------------
Reporter: abetkin | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 4.0
Severity: Release blocker | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by abetkin):

* status: new => closed
* resolution: => invalid


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

Django

unread,
May 17, 2022, 7:10:07 PM5/17/22
to django-...@googlegroups.com
#33716: Async-capable middleware is not async-capable
-------------------------------+------------------------------------
Reporter: abetkin | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by abetkin):

* severity: Release blocker => Normal


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

Reply all
Reply to author
Forward
0 new messages