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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions debug_toolbar/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,18 @@ def js_mimetype_check(app_configs, **kwargs):
)
]
return []


@register()
def check_settings(app_configs, **kwargs):
errors = []
USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
if "OBSERVE_REQUEST_CALLBACK" in USER_CONFIG:
errors.append(
Warning(
"The deprecated OBSERVE_REQUEST_CALLBACK setting is present in DEBUG_TOOLBAR_CONFIG.",
hint="Use the UPDATE_ON_FETCH and/or SHOW_TOOLBAR_CALLBACK settings instead.",
id="debug_toolbar.W008",
)
)
return errors
2 changes: 1 addition & 1 deletion debug_toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ def observe_request(request):
"""
Determine whether to update the toolbar from a client side request.
"""
return not DebugToolbar.is_toolbar_request(request)
return True
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Pending
:class:`StaticFilesPanel <debug_toolbar.panels.staticfiles.StaticFilesPanel>`
since that check is made redundant by a similar check in Django 4.0 and
later.
* Deprecated the ``OBSERVE_REQUEST_CALLBACK`` setting and added check
``debug_toolbar.W008`` to warn when it is present in
``DEBUG_TOOLBAR_SETTINGS``.

4.3.0 (2024-02-01)
------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ Django Debug Toolbar setup and configuration:
* **debug_toolbar.W007**: JavaScript files are resolving to the wrong content
type. Refer to :external:ref:`Django's explanation of
mimetypes on Windows <staticfiles-development-view>`.
* **debug_toolbar.W008**: The deprecated ``OBSERVE_REQUEST_CALLBACK`` setting
is present in ``DEBUG_TOOLBAR_CONFIG``. Use the ``UPDATE_ON_FETCH`` and/or
``SHOW_TOOLBAR_CALLBACK`` settings instead.
10 changes: 7 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ Toolbar options

Default: ``'debug_toolbar.toolbar.observe_request'``

.. note::

This setting is deprecated in favor of the ``UPDATE_ON_FETCH`` and
``SHOW_TOOLBAR_CALLBACK`` settings.

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

.. _TOOLBAR_LANGUAGE:

Expand Down
8 changes: 8 additions & 0 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,11 @@ def test_check_w007_invalid(self, mocked_guess_type):
)
],
)

@override_settings(
DEBUG_TOOLBAR_CONFIG={"OBSERVE_REQUEST_CALLBACK": lambda request: False}
)
def test_observe_request_callback_specified(self):
errors = run_checks()
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0].id, "debug_toolbar.W008")