Skip to content

Commit

Permalink
Deprecate OBSERVE_REQUEST_CALLBACK
Browse files Browse the repository at this point in the history
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
  • Loading branch information
living180 committed Mar 11, 2024
1 parent 68039c6 commit cfbad48
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
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
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.
5 changes: 5 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ 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 implementation
always returns ``True``.
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")

0 comments on commit cfbad48

Please sign in to comment.