Skip to content

Commit 716b962

Browse files
JacobCoffeeclaude
andcommitted
fix: guard debug_toolbar import for environments without dev extras
Guard debug_toolbar imports in both local.py and urls.py with ModuleNotFoundError checks scoped to the debug_toolbar module name. This prevents startup failures in CI and Docker where dev extras aren't installed, while still surfacing real import errors from within debug_toolbar itself (e.g. missing transitive dependencies). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1b9afc1 commit 716b962

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

pydotorg/settings/local.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@
2525
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
2626

2727

28-
INSTALLED_APPS += [
29-
"debug_toolbar",
30-
]
31-
32-
MIDDLEWARE += [
33-
"debug_toolbar.middleware.DebugToolbarMiddleware",
34-
]
28+
try:
29+
import debug_toolbar # noqa: F401
30+
31+
INSTALLED_APPS += [
32+
"debug_toolbar",
33+
]
34+
35+
MIDDLEWARE += [
36+
"debug_toolbar.middleware.DebugToolbarMiddleware",
37+
]
38+
except ModuleNotFoundError as exc:
39+
if exc.name != "debug_toolbar":
40+
raise
3541

3642
CACHES = {
3743
"default": {

pydotorg/urls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373

7474
if settings.DEBUG:
7575
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
76-
import debug_toolbar
76+
try:
77+
import debug_toolbar
7778

78-
urlpatterns = [path("__debug__/", include(debug_toolbar.urls)), *urlpatterns]
79+
urlpatterns = [path("__debug__/", include(debug_toolbar.urls)), *urlpatterns]
80+
except ModuleNotFoundError as exc:
81+
if exc.name != "debug_toolbar":
82+
raise

0 commit comments

Comments
 (0)