Opened 3 years ago

Last modified 3 years ago

#33716 closed New feature

Async-capable middleware is not async-capable — at Version 3

Reported by: abetkin Owned by: nobody
Component: Uncategorized Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by abetkin)

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

Change History (4)

by abetkin, 3 years ago

Attachment: bug.png added

comment:1 by abetkin, 3 years ago

Description: modified (diff)

comment:2 by abetkin, 3 years ago

Description: modified (diff)

comment:3 by abetkin, 3 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Note: See TracTickets for help on using tickets.
Back to Top