Skip to content

Commit db03887

Browse files
Deprecate RedirectsPanel and update tests for deprecation warning
1 parent 13fc5c0 commit db03887

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

debug_toolbar/panels/redirects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from inspect import iscoroutine
23

34
from django.template.response import SimpleTemplateResponse
@@ -17,6 +18,17 @@ class RedirectsPanel(Panel):
1718

1819
nav_title = _("Intercept redirects")
1920

21+
def __init__(self, *args, **kwargs):
22+
super().__init__(*args, **kwargs)
23+
warnings.warn(
24+
"The RedirectsPanel is deprecated and will be removed in a future version. "
25+
"The HistoryPanel now provides the ability to view toolbar data for redirected requests. "
26+
"If you still have a use case for this panel, please comment on "
27+
"https://github.com/django-commons/django-debug-toolbar/issues/2216",
28+
DeprecationWarning,
29+
stacklevel=2,
30+
)
31+
2032
def _process_response(self, response):
2133
"""
2234
Common response processing logic.

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Pending
1515
* Added ``CommunityPanel`` containing links to documentation and resources.
1616
* Added how to generate the documentation locally to the contributing
1717
documentation.
18+
* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing
19+
toolbar data from redirected requests.
1820

1921
6.0.0 (2025-07-22)
2022
------------------

docs/panels.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ Redirects
120120

121121
.. class:: debug_toolbar.panels.redirects.RedirectsPanel
122122

123+
.. deprecated:: 6.0
124+
125+
The RedirectsPanel is deprecated and will be removed in a future version.
126+
The HistoryPanel now provides the ability to view toolbar data for redirected
127+
requests. If you have a use case for this panel, please comment on the
128+
GitHub issue <https://github.com/django-commons/django-debug-toolbar/issues/2216>`_.
129+
123130
When this panel is enabled, the debug toolbar will show an intermediate page
124131
upon redirect so you can view any debug information prior to redirecting. This
125132
page will provide a link to the redirect destination you can follow when

tests/panels/test_redirects.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import warnings
23

34
from django.conf import settings
45
from django.http import HttpResponse
@@ -12,6 +13,12 @@
1213
class RedirectsPanelTestCase(BaseTestCase):
1314
panel_id = RedirectsPanel.panel_id
1415

16+
def setUp(self):
17+
# Suppress the deprecation warning during setup
18+
with warnings.catch_warnings():
19+
warnings.simplefilter("ignore", DeprecationWarning)
20+
super().setUp()
21+
1522
def test_regular_response(self):
1623
not_redirect = HttpResponse()
1724
self._get_response = lambda request: not_redirect
@@ -100,3 +107,14 @@ def test_original_response_preserved(self):
100107
self.assertEqual(
101108
response.original_response.get("Location"), "http://somewhere/else/"
102109
)
110+
111+
def test_deprecation_warning(self):
112+
"""Test that a deprecation warning is shown when RedirectsPanel is instantiated."""
113+
from debug_toolbar.toolbar import DebugToolbar
114+
115+
with self.assertWarns(DeprecationWarning) as cm:
116+
toolbar = DebugToolbar(self.request, self._get_response)
117+
toolbar.get_panel_by_id(RedirectsPanel.panel_id)
118+
119+
self.assertIn("RedirectsPanel is deprecated", str(cm.warning))
120+
self.assertIn("HistoryPanel", str(cm.warning))

0 commit comments

Comments
 (0)