Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate OBSERVE_REQUEST_CALLBACK setting #1895

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

living180
Copy link
Contributor

Description

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

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
With the addition of the UPDATE_ON_FETCH setting, the
OBSERVE_REQUEST_CALLBACK setting is redundant.  Thus add a check
debug_toolbar.W008 to warn if it is present in DEBUG_TOOLBAR_CONFIG,
but do not remove it yet.

See django-commons#1886
Copy link
Member

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thank you for cleaning this up @living180! I'll leave it open for a day or two to give Matthias time to review, but will otherwise merge it.

@matthiask matthiask merged commit c2daf3a into django-commons:main Mar 18, 2024
26 checks passed
@matthiask
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants