Skip to content

Support for request-level urlconf overrides #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion debug_toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def is_toolbar_request(cls, request):
# The primary caller of this function is in the middleware which may
# not have resolver_match set.
try:
resolver_match = request.resolver_match or resolve(request.path)
resolver_match = request.resolver_match or resolve(
request.path, getattr(request, "urlconf", None)
)
except Resolver404:
return False
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name
Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Next version
* Fixed ``RENDER_PANELS`` functionality so that when ``True`` panels are
rendered during the request and not loaded asynchronously.
* HistoryPanel now shows status codes of responses.
* Support ``request.urlconf`` override when checking for toolbar requests.


3.2.1 (2021-04-14)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def test_is_toolbar_request_without_djdt_urls(self):
self.request.path = "/render_panel/"
self.assertFalse(self.toolbar.is_toolbar_request(self.request))

@override_settings(ROOT_URLCONF="tests.urls_invalid")
def test_is_toolbar_request_override_request_urlconf(self):
"""Test cases when the toolbar URL is configured on the request."""
self.request.path = "/__debug__/render_panel/"
self.assertFalse(self.toolbar.is_toolbar_request(self.request))

# Verify overriding the urlconf on the request is valid.
self.request.urlconf = "tests.urls"
self.request.path = "/__debug__/render_panel/"
self.assertTrue(self.toolbar.is_toolbar_request(self.request))


@override_settings(DEBUG=True)
class DebugToolbarIntegrationTestCase(IntegrationTestCase):
Expand Down