| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Head branch was pushed to by a user without write access
When an async Django middleware defines an `async def` hook such as
`process_view` or `process_exception`, the SDK wrapped it in a synchronous
function. That hid the coroutine from Django's `iscoroutinefunction` check in
`BaseHandler.load_middleware`, so Django wrapped the hook in `SyncToAsync` and
called it synchronously. The underlying coroutine was then never awaited, and
the request failed with:
```
ValueError: The view ... didn't return an HttpResponse object.
It returned an unawaited coroutine instead.
```
`_get_wrapped_method` in the Django middleware integration now produces an
`async def` wrapper when the wrapped middleware hook is a coroutine function,
instead of always producing a synchronous wrapper.
Head branch was pushed to by a user without write access
…getsentry#6698) Stop wrapping async middleware hooks in sync functions to prevent misclassifications due to `iscoroutinefunction()` checks within Django. Co-authored-by: Romain Fliedel <romain@oqee.tv>
| Back | FazBrowse Home | New Git URL |
Description
When an async Django middleware defines an async def hook such as process_view or process_exception, the SDK wrapped it in a synchronous function. That hid the coroutine from Django's iscoroutinefunction check in BaseHandler.load_middleware, so Django wrapped the hook in SyncToAsync and called it synchronously. The underlying coroutine was then never awaited, and the request failed with:
ValueError: The view ... didn't return an HttpResponse object. It returned an unawaited coroutine instead._get_wrapped_method in the Django middleware integration now produces an async def wrapper when the wrapped middleware hook is a coroutine function, instead of always producing a synchronous wrapper.
Issues
Discussed on Discord https://discord.com/channels/621778831602221064/1521260879218348103