django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

Add test for async views and ORM usage.

Open matthiask opened this issue 2 years ago • 1 comments

matthiask avatar Aug 01 '23 17:08 matthiask

I have started digging into tracking SQL statements for a bit and I'm unsure how to proceed.

ORM queries are started inside a thread pool executor when using an ASGI server. I have no idea how we could go from the DB cursor to the view which originally caused or started the request.

Operating systems don't generally store data about where threads come from, async tasks do not generally have an accessible parent or task group. Instrumentation is currently enabled per thread, but that also doesn't work when the activation happens in a different thread (or does it? maybe the sync_to_async(..., thread_sensitive=True) thing helps us and we can just assume we're in the correct thread? But then we still don't know to which view we belong?)

(Things are complicated even more because views can kick off tasks which will produce ORM queries after the response has been returned to the client...)

matthiask avatar Aug 01 '23 17:08 matthiask