Opened 3 years ago
Last modified 3 years ago
#33716 closed New feature
Async-capable middleware is not async-capable — at Initial Version
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
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