Skip to content

Commit 4baa099

Browse files
Deprecate RedirectsPanel in favor of history panel.
Log a deprecation warning and include warning on the panel itself. It asks users to comment on the GitHub issue if the redirects panel is still a requirement for them.
1 parent 6ef77a1 commit 4baa099

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-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.

debug_toolbar/templates/debug_toolbar/redirect.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,68 @@
44
<head>
55
<title>Django Debug Toolbar Redirects Panel: {{ status_line }}</title>
66
<script{% if toolbar.csp_nonce %} nonce="{{ toolbar.csp_nonce }}"{% endif %} type="module" src="{% static 'debug_toolbar/js/redirect.js' %}" async></script>
7+
<style>
8+
.djdt-deprecation-warning {
9+
--djdt-warning-bg: #fff3cd;
10+
--djdt-warning-text: #856404;
11+
--djdt-warning-accent: #f1c40f;
12+
--djdt-warning-link: #0056b3;
13+
--djdt-warning-link-hover: #003d7a;
14+
--djdt-warning-strong: #000;
15+
--djdt-warning-shadow: rgba(0, 0, 0, 0.1);
16+
17+
position: relative;
18+
background-color: var(--djdt-warning-bg);
19+
color: var(--djdt-warning-text);
20+
border-left: 0.25em solid var(--djdt-warning-accent);
21+
padding: 1em;
22+
margin: 1.5em 0;
23+
border-radius: 0.25em;
24+
box-shadow:
25+
0 0.0625em 0.1875em var(--djdt-warning-shadow),
26+
0 0.0625em 0.125em var(--djdt-warning-shadow);
27+
font-family: var(--djdt-font-family-primary);
28+
font-size: 0.875em;
29+
line-height: 1.5;
30+
}
31+
32+
.djdt-deprecation-warning::before {
33+
content: "⚠️";
34+
font-size: 1.125em;
35+
margin-right: 0.75em;
36+
vertical-align: middle;
37+
}
38+
39+
.djdt-deprecation-warning a {
40+
color: var(--djdt-warning-link);
41+
text-decoration: none;
42+
font-weight: 500;
43+
border-bottom: 0.0625em solid currentColor;
44+
padding-bottom: 0.0625em;
45+
transition: all 0.2s ease;
46+
}
47+
48+
.djdt-deprecation-warning a:hover {
49+
color: var(--djdt-warning-link-hover);
50+
border-bottom-width: 0.125em;
51+
}
52+
53+
.djdt-deprecation-warning strong {
54+
color: var(--djdt-warning-strong);
55+
font-weight: 600;
56+
}
57+
</style>
758
</head>
859
<body>
60+
<div class="djdt-deprecation-warning">
61+
<strong>{% translate "WARNING:" %}</strong>
62+
{% blocktranslate with issue_url="https://github.com/django-commons/django-debug-toolbar/issues/2216" %}
63+
The RedirectsPanel is deprecated and will be removed in a future version. The HistoryPanel
64+
now provides the ability to view toolbar data for redirected requests. If you still have a
65+
use case for this panel, please comment on this <a target="_blank" rel="noopener noreferrer"
66+
href="{{ issue_url }}">issue</a>.
67+
{% endblocktranslate %}
68+
</div>
969
<h1>{{ status_line }}</h1>
1070
<h2>{% translate "Location:" %} <a id="redirect_to" href="{{ redirect_to }}">{{ redirect_to }}</a></h2>
1171
<p class="notice">

docs/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Change log
44
Pending
55
-------
66

7+
* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing
8+
toolbar data from redirected requests.
9+
710
6.1.0 (2025-10-30)
811
------------------
912

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,17 +1,25 @@
11
import copy
2+
import warnings
23

34
from django.conf import settings
45
from django.http import HttpResponse
56
from django.test import AsyncRequestFactory
67

78
from debug_toolbar.panels.redirects import RedirectsPanel
9+
from debug_toolbar.toolbar import DebugToolbar
810

911
from ..base import BaseTestCase
1012

1113

1214
class RedirectsPanelTestCase(BaseTestCase):
1315
panel_id = RedirectsPanel.panel_id
1416

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+
1523
def test_regular_response(self):
1624
not_redirect = HttpResponse()
1725
self._get_response = lambda request: not_redirect
@@ -100,3 +108,13 @@ def test_original_response_preserved(self):
100108
self.assertEqual(
101109
response.original_response.get("Location"), "http://somewhere/else/"
102110
)
111+
112+
def test_deprecation_warning(self):
113+
"""Test that a deprecation warning is shown when RedirectsPanel is instantiated."""
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)