Skip to content

Commit

Permalink
Merge pull request #1895 from living180/observe_request_callback
Browse files Browse the repository at this point in the history
Deprecate OBSERVE_REQUEST_CALLBACK setting
  • Loading branch information
matthiask committed Mar 18, 2024
2 parents 3097692 + cfbad48 commit c2daf3a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
15 changes: 15 additions & 0 deletions debug_toolbar/apps.py
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
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
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
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
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
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")

0 comments on commit c2daf3a

Please sign in to comment.