jazzband / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
7.97k stars 1.03k forks source link

Async compatible debug-toolbar middleware #1938

Open salty-ivy opened 1 week ago

salty-ivy commented 1 week ago

Description

GSoC 2024

This PR aims to add async compatibility in django-debug-toolbar middleware

Fixes # (issue)

Checklist:

salty-ivy commented 6 days ago

LGTM. I wonder how the panels can differentiate in process_request between the sync and async version.

panels would receive either WSGIRequest or ASGIRequest ( not async ) instance which are subclasses of HttpRequest.

Also, awaiting def process_request (NOT async def process_request) looks a bit strange, but seems fine to me after thinking about it a bit.

process_request call of panels would ultimately reach down to view via chain of calls of both panels and then middlewares, the response will always be adapted to async by adapt_method_mode that has to be awaited.

https://github.com/django/django/blob/e56a32b89bb7fadffdfaa2cdf12b4863ccd5af9b/django/core/handlers/base.py#L104

it even adapts the view if its not async def the response will be adapted to async coroutines if the receiving middleware is async and we are running in async context ( if both conditions are true ).

https://github.com/django/django/blob/e56a32b89bb7fadffdfaa2cdf12b4863ccd5af9b/django/core/handlers/base.py#L54

this is my overall understanding so far.