Skip to content

Commit 68039c6

Browse files
committed
Simplify default OBSERVE_REQUEST_CALLBACK behavior
The previous implementation of observe_request(), the default callback for OBSERVE_REQUEST_CALLBACK, was checking for DebugToolbar.is_toolbar_request() and returning True only if that method returned False. However, this is actually unneeded, because DebugToolbarMiddleware never instruments its own requests. If DebugToolbar.is_toolbar_request() returns True for a given request, DebugToolbarMiddleware will return early without performing any instrumentation or processing on the request [1]. In this case, the OBSERVE_REQUEST_CALLBACK callback never gets called, because it only gets called via the HistoryPanel.get_headers() method [2]. The .get_headers() method is only called by DebugToolbarMiddleware after the early return mentioned above [3]. Thus if OBSERVE_REQUEST_CALLBACK is called, it must be the case that DebugToolbar.is_toolbar_request() is False for the current request. Therefore observe_request() can be simplified to always return True without changing its behavior. [1] https://github.com/jazzband/django-debug-toolbar/blob/c688ce4ad7d18c5ecb800869298ca8cf6c08be1d/debug_toolbar/middleware.py#L48-L49 [2] https://github.com/jazzband/django-debug-toolbar/blob/c688ce4ad7d18c5ecb800869298ca8cf6c08be1d/debug_toolbar/panels/history/panel.py#L23-L29 [3] https://github.com/jazzband/django-debug-toolbar/blob/c688ce4ad7d18c5ecb800869298ca8cf6c08be1d/debug_toolbar/middleware.py#L76-L77
1 parent cfd4801 commit 68039c6

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

debug_toolbar/toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,4 @@ def observe_request(request):
185185
"""
186186
Determine whether to update the toolbar from a client side request.
187187
"""
188-
return not DebugToolbar.is_toolbar_request(request)
188+
return True

docs/configuration.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ Toolbar options
146146
Default: ``'debug_toolbar.toolbar.observe_request'``
147147

148148
This is the dotted path to a function used for determining whether the
149-
toolbar should update on AJAX requests or not. The default checks are that
150-
the request doesn't originate from the toolbar itself, EG that
151-
``is_toolbar_request`` is false for a given request.
149+
toolbar should update on AJAX requests or not. The default implementation
150+
always returns ``True``.
152151

153152
.. _TOOLBAR_LANGUAGE:
154153

0 commit comments

Comments
 (0)