Skip to content

Commit 1239499

Browse files
authored
fix(spotlight): Make Django middleware init even more defensive (#3870)
I just got faced with a situation where even trying to do `settings.DEBUG` may trigger a Django exception if the settings are not loaded yet, hence widening the `capture_internal_exceptions()` scope for this.
1 parent 6448c70 commit 1239499

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sentry_sdk/spotlight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ def setup_spotlight(options):
210210
if not isinstance(url, str):
211211
return None
212212

213-
if (
214-
settings is not None
215-
and settings.DEBUG
216-
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
217-
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
218-
):
219-
with capture_internal_exceptions():
213+
with capture_internal_exceptions():
214+
if (
215+
settings is not None
216+
and settings.DEBUG
217+
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
218+
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
219+
):
220220
middleware = settings.MIDDLEWARE
221221
if DJANGO_SPOTLIGHT_MIDDLEWARE_PATH not in middleware:
222222
settings.MIDDLEWARE = type(middleware)(

0 commit comments

Comments
 (0)