Skip to content

Commit 5377514

Browse files
committed
Deprecate OBSERVE_REQUEST_CALLBACK
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
1 parent 68039c6 commit 5377514

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

debug_toolbar/apps.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,18 @@ def js_mimetype_check(app_configs, **kwargs):
206206
)
207207
]
208208
return []
209+
210+
211+
@register()
212+
def check_settings(app_configs, **kwargs):
213+
errors = []
214+
USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
215+
if "OBSERVE_REQUEST_CALLBACK" in USER_CONFIG:
216+
errors.append(
217+
Warning(
218+
"The deprecated OBSERVE_REQUEST_CALLBACK setting is present in DEBUG_TOOLBAR_CONFIG.",
219+
hint="Use the UPDATE_ON_FETCH and/or SHOW_TOOLBAR_CALLBACK settings instead.",
220+
id="debug_toolbar.W008",
221+
)
222+
)
223+
return errors

docs/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Pending
1717
:class:`StaticFilesPanel <debug_toolbar.panels.staticfiles.StaticFilesPanel>`
1818
since that check is made redundant by a similar check in Django 4.0 and
1919
later.
20+
* Deprecated the ``OBSERVE_REQUEST_CALLBACK`` setting and added check
21+
``debug_toolbar.W008`` to warn when it is specified in
22+
``DEBUG_TOOLBAR_SETTINGS``.
2023

2124
4.3.0 (2024-02-01)
2225
------------------

docs/checks.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ Django Debug Toolbar setup and configuration:
2121
* **debug_toolbar.W007**: JavaScript files are resolving to the wrong content
2222
type. Refer to :external:ref:`Django's explanation of
2323
mimetypes on Windows <staticfiles-development-view>`.
24+
* **debug_toolbar.W008**: The deprecated ``OBSERVE_REQUEST_CALLBACK`` setting
25+
is present in ``DEBUG_TOOLBAR_CONFIG``. Use the ``UPDATE_ON_FETCH`` and/or
26+
``SHOW_TOOLBAR_CALLBACK`` settings instead.

docs/configuration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ Toolbar options
145145

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

148+
.. note::
149+
150+
This setting is deprecated in favor of the ``UPDATE_ON_FETCH`` and
151+
``SHOW_TOOLBAR_CALLBACK`` settings.
152+
148153
This is the dotted path to a function used for determining whether the
149154
toolbar should update on AJAX requests or not. The default implementation
150155
always returns ``True``.

tests/test_checks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,11 @@ def test_check_w007_invalid(self, mocked_guess_type):
235235
)
236236
],
237237
)
238+
239+
@override_settings(
240+
DEBUG_TOOLBAR_CONFIG={"OBSERVE_REQUEST_CALLBACK": lambda request: False}
241+
)
242+
def test_observe_request_callback_specified(self):
243+
errors = run_checks()
244+
self.assertEqual(len(errors), 1)
245+
self.assertEqual(errors[0].id, "debug_toolbar.W008")

0 commit comments

Comments
 (0)