fix(dev): simplify Debug Toolbar wiring (review followups)
Three followups on 7075269: - config/urls.py: drop dead try/except ImportError fallback. The settings.py gate already guarantees debug_toolbar is importable before we reach this line, so the except branch was unreachable and the re-import of include/path was redundant (both imported at top of file). - config/settings.py: SHOW_TOOLBAR_CALLBACK now returns True unconditionally. The triple gate passed at settings-load time, so re-checking DEBUG and _IS_DEV inside the lambda was redundant. Comment corrected — the callback has nothing to do with "stale cached pages". - requirements.txt: inline comment noting django-debug-toolbar is dev-only and gated. No behavioural change. Tests: 68/68. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7075269a07
commit
2731ac9ffd
@ -334,7 +334,9 @@ if DEBUG and _IS_DEV and not _IS_RUNNING_TESTS:
|
||||
# Don't auto-collapse the SQL panel — the SQL count is the
|
||||
# main thing we check on every page.
|
||||
'SHOW_COLLAPSED': False,
|
||||
# Explicit check so the toolbar ONLY renders when the hosting
|
||||
# flags are still set (guards against stale cached pages).
|
||||
'SHOW_TOOLBAR_CALLBACK': lambda request: DEBUG and _IS_DEV,
|
||||
# This callback is invoked per-request by the toolbar's middleware.
|
||||
# Since we only REACH this config block when the triple gate
|
||||
# (DEBUG + _IS_DEV + not running tests) already passed at settings
|
||||
# load time, there's nothing to re-check here — just return True.
|
||||
'SHOW_TOOLBAR_CALLBACK': lambda request: True,
|
||||
}
|
||||
|
||||
@ -15,11 +15,10 @@ if settings.DEBUG:
|
||||
|
||||
# === DEV-ONLY: Django Debug Toolbar URL include ===
|
||||
# Matches the conditional load in settings.py. No-op in prod.
|
||||
# The settings.py gate already guarantees debug_toolbar is importable
|
||||
# by the time we get here, so no try/except is needed. If we ever
|
||||
# downgrade to a toolbar version older than v4.0 (which introduced
|
||||
# debug_toolbar_urls), swap this for `path('__debug__/', include(debug_toolbar.urls))`.
|
||||
if 'debug_toolbar' in settings.INSTALLED_APPS:
|
||||
try:
|
||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||
urlpatterns += debug_toolbar_urls()
|
||||
except ImportError:
|
||||
import debug_toolbar
|
||||
from django.urls import include, path
|
||||
urlpatterns += [path('__debug__/', include(debug_toolbar.urls))]
|
||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||
urlpatterns += debug_toolbar_urls()
|
||||
@ -3,4 +3,4 @@ mysqlclient==2.2.7
|
||||
python-dotenv==1.1.1
|
||||
pillow==12.1.1
|
||||
weasyprint==68.1
|
||||
django-debug-toolbar==6.0.0
|
||||
django-debug-toolbar==6.0.0 # dev-only — gated in config/settings.py, never active in prod
|
||||
Loading…
x
Reference in New Issue
Block a user