Skip to content

Commit 4c70a42

Browse files
Emit RedirectsPanel warning on usage rather than set up. (#2326)
* Emit RedirectsPanel warning on usage rather than set up. * Remove stale test. The test's doc string was out of alignment with what the test actually did.
1 parent 61195d0 commit 4c70a42

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

debug_toolbar/panels/redirects.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ class RedirectsPanel(Panel):
1818

1919
nav_title = _("Intercept redirects")
2020

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-
3221
def _process_response(self, response):
3322
"""
3423
Common response processing logic.
@@ -71,4 +60,13 @@ def get_interception_response(self, response, redirect_to):
7160
response = SimpleTemplateResponse("debug_toolbar/redirect.html", context)
7261
response.cookies = cookies
7362
response.original_response = original_response
63+
64+
warnings.warn(
65+
"The RedirectsPanel is deprecated and will be removed in a future version. "
66+
"The HistoryPanel now provides the ability to view toolbar data for redirected requests. "
67+
"If you still have a use case for this panel, please comment on "
68+
"https://github.com/django-commons/django-debug-toolbar/issues/2216",
69+
DeprecationWarning,
70+
stacklevel=2,
71+
)
7472
return response

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Pending
1212
* Added translations for Lithuanian, Turkish and Uzbek.
1313
* Update the translations.
1414
* Expose a ``py.typed`` marker file.
15+
* Updated ``RedirectsPanel`` to emit the deprecation warning when it's used
16+
rather than on instantiation.
1517

1618
6.2.0 (2026-01-20)
1719
------------------

tests/panels/test_redirects.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import copy
2-
import warnings
32

43
from django.conf import settings
54
from django.http import HttpResponse
65
from django.test import AsyncRequestFactory
76

87
from debug_toolbar.panels.redirects import RedirectsPanel
9-
from debug_toolbar.toolbar import DebugToolbar
108

119
from ..base import BaseTestCase
1210

1311

1412
class RedirectsPanelTestCase(BaseTestCase):
1513
panel_id = RedirectsPanel.panel_id
1614

17-
def setUp(self):
18-
# Suppress the deprecation warning during setup
19-
with warnings.catch_warnings():
20-
warnings.simplefilter("ignore", DeprecationWarning)
21-
super().setUp()
22-
2315
def test_regular_response(self):
2416
not_redirect = HttpResponse()
2517
self._get_response = lambda request: not_redirect
@@ -70,18 +62,6 @@ def test_unknown_status_code_with_reason(self):
7062
response = self.panel.process_request(self.request)
7163
self.assertContains(response, "369 Look Ma!")
7264

73-
def test_insert_content(self):
74-
"""
75-
Test that the panel only inserts content after generate_stats and
76-
not the process_request.
77-
"""
78-
redirect = HttpResponse(status=304)
79-
self._get_response = lambda request: redirect
80-
response = self.panel.process_request(self.request)
81-
self.assertIsNotNone(response)
82-
response = self.panel.generate_stats(self.request, redirect)
83-
self.assertIsNone(response)
84-
8565
async def test_async_compatibility(self):
8666
redirect = HttpResponse(status=302)
8767

@@ -110,11 +90,13 @@ def test_original_response_preserved(self):
11090
)
11191

11292
def test_deprecation_warning(self):
113-
"""Test that a deprecation warning is shown when RedirectsPanel is instantiated."""
93+
"""Test that a deprecation warning is shown when RedirectsPanel used."""
94+
redirect = HttpResponse(status=304)
95+
redirect["Location"] = "http://somewhere/else/"
96+
self._get_response = lambda request: redirect
11497

11598
with self.assertWarns(DeprecationWarning) as cm:
116-
toolbar = DebugToolbar(self.request, self._get_response)
117-
toolbar.get_panel_by_id(RedirectsPanel.panel_id)
99+
self.panel.process_request(self.request)
118100

119101
self.assertIn("RedirectsPanel is deprecated", str(cm.warning))
120102
self.assertIn("HistoryPanel", str(cm.warning))

0 commit comments

Comments
 (0)