django-debug-toolbar
                                
                                 django-debug-toolbar copied to clipboard
                                
                                    django-debug-toolbar copied to clipboard
                            
                            
                            
                        gather information from async functions
If some queries are executed in async mode, these queries are missing in the panel. How can we collect these?
data = asyncio.run(parallel_calc_aggregations(queryset, aggregations))
note1: I am using django-debug-toolbar via django-graphiql-debug-toolbar
note2: all queries are inside function wrapped by sync_to_async
The same issue exists when graphql ThreadExecutor is used. read more about graphql executors graphql-314
The toolbar currently does not support async and the collection of statistics is tightly coupled to a request. If you do end up diving into how to modify the toolbar to collect this information, we'd appreciate any conclusions or findings of yours.
Is there any decorator function we can add around these functions and collect data required by debug-toolbar?
@collect_debug_toolbar_data
def get_data():
  # pure django
async def async_get_data():
      return await sync_to_async(get_data, thread_sensitive=False)()
async def parallel_get_data():
  return await asyncio.gather(async_get_data(), async_get_data(), async_get_data())
data = asyncio.run(parallel_get_data())
Currently the only API for collecting the data is done via the middleware and the methods on the panels themselves.
maybe it's possible to wrap/runtime patch sync_to_async. all async function using django orm should use this function and without sync_to_async function causing error.
def sync_to_async(func=None, thread_sensitive=True):
    if func is None:
        return lambda f: SyncToAsync(f, thread_sensitive=thread_sensitive)
    return SyncToAsync(func, thread_sensitive=thread_sensitive)
the func argument is a simple sync function
Until async views are supported can the toolbar at least be kept from erroring out on aync views?
@michaelurban that's a good idea. Or at least log some type of message. Would you be able to write up a PR to introduce that feature?
@tim-schilling Sorry, I don't have the time. I'm working 80+ hour weeks for the foreseeable future.