Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions debug_toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.dispatch import Signal
from django.template import TemplateSyntaxError
from django.template.loader import render_to_string
from django.urls import include, path, re_path, resolve
from django.urls import get_script_prefix, include, path, re_path, resolve
from django.urls.exceptions import Resolver404
from django.utils.module_loading import import_string
from django.utils.translation import get_language, override as lang_override
Expand Down Expand Up @@ -165,7 +165,8 @@ def is_toolbar_request(cls, request):
# not have resolver_match set.
try:
resolver_match = request.resolver_match or resolve(
request.path, getattr(request, "urlconf", None)
request.path.replace(get_script_prefix(), "/", 1),
getattr(request, "urlconf", None),
)
except Resolver404:
return False
Expand Down
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change log
Pending
-------

* Fixed internal toolbar requests being instrumented if the Django setting
``FORCE_SCRIPT_NAME`` was set.

4.4.6 (2024-07-10)
------------------

Expand Down
17 changes: 17 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ def test_is_toolbar_request_override_request_urlconf(self):
self.request.path = "/__debug__/render_panel/"
self.assertTrue(self.toolbar.is_toolbar_request(self.request))

@patch("debug_toolbar.toolbar.get_script_prefix", return_value="/path/")
def test_is_toolbar_request_with_script_prefix(self, mocked_get_script_prefix):
"""
Test cases when Django is running under a path prefix, such as via the
FORCE_SCRIPT_NAME setting.
"""
self.request.path = "/path/__debug__/render_panel/"
self.assertTrue(self.toolbar.is_toolbar_request(self.request))

self.request.path = "/path/invalid/__debug__/render_panel/"
self.assertFalse(self.toolbar.is_toolbar_request(self.request))

self.request.path = "/path/render_panel/"
self.assertFalse(self.toolbar.is_toolbar_request(self.request))

self.assertEqual(mocked_get_script_prefix.call_count, 3)

def test_data_gone(self):
response = self.client.get(
"/__debug__/render_panel/?store_id=GONE&panel_id=RequestPanel"
Expand Down