Skip to content

Commit 9a232bc

Browse files
committed
Add test confirming urlconf override functionality.
Update docs for urlconf override per request.
1 parent a166c30 commit 9a232bc

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

debug_toolbar/toolbar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def is_toolbar_request(cls, request):
146146
# The primary caller of this function is in the middleware which may
147147
# not have resolver_match set.
148148
try:
149-
resolver_match = request.resolver_match or resolve(request.path, getattr(request, 'urlconf', None))
149+
resolver_match = request.resolver_match or resolve(
150+
request.path, getattr(request, "urlconf", None)
151+
)
150152
except Resolver404:
151153
return False
152154
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Next version
1111
* Fixed ``RENDER_PANELS`` functionality so that when ``True`` panels are
1212
rendered during the request and not loaded asynchronously.
1313
* HistoryPanel now shows status codes of responses.
14+
* Support ``request.urlconf`` override when checking for toolbar requests.
1415

1516

1617
3.2.1 (2021-04-14)

tests/test_integration.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ def test_is_toolbar_request_without_djdt_urls(self):
121121
self.request.path = "/render_panel/"
122122
self.assertFalse(self.toolbar.is_toolbar_request(self.request))
123123

124+
@override_settings(ROOT_URLCONF="tests.urls_invalid")
125+
def test_is_toolbar_request_override_request_urlconf(self):
126+
"""Test cases when the toolbar URL is configured on the request."""
127+
self.request.path = "/__debug__/render_panel/"
128+
self.assertFalse(self.toolbar.is_toolbar_request(self.request))
129+
130+
# Verify overriding the urlconf on the request is valid.
131+
self.request.urlconf = "tests.urls"
132+
self.request.path = "/__debug__/render_panel/"
133+
self.assertTrue(self.toolbar.is_toolbar_request(self.request))
134+
124135

125136
@override_settings(DEBUG=True)
126137
class DebugToolbarIntegrationTestCase(IntegrationTestCase):

0 commit comments

Comments
 (0)