Skip to content

Commit fafe8f6

Browse files
authored
fix: Always set _spotlight_url (#4186)
The conditional early exit in `SpotlightMiddleware` may cause attribute access errors when trying to check if `_spotlight_url` is set or not. This patch sets it to `None` explicitly at class level.
1 parent 4fbcbf0 commit fafe8f6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sentry_sdk/spotlight.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def capture_envelope(self, envelope):
8282

8383
class SpotlightMiddleware(MiddlewareMixin): # type: ignore[misc]
8484
_spotlight_script = None # type: Optional[str]
85+
_spotlight_url = None # type: Optional[str]
8586

8687
def __init__(self, get_response):
8788
# type: (Self, Callable[..., HttpResponse]) -> None
@@ -103,7 +104,7 @@ def __init__(self, get_response):
103104
@property
104105
def spotlight_script(self):
105106
# type: (Self) -> Optional[str]
106-
if self._spotlight_script is None:
107+
if self._spotlight_url is not None and self._spotlight_script is None:
107108
try:
108109
spotlight_js_url = urllib.parse.urljoin(
109110
self._spotlight_url, SPOTLIGHT_JS_ENTRY_PATH
@@ -173,7 +174,7 @@ def process_response(self, _request, response):
173174

174175
def process_exception(self, _request, exception):
175176
# type: (Self, HttpRequest, Exception) -> Optional[HttpResponseServerError]
176-
if not settings.DEBUG:
177+
if not settings.DEBUG or not self._spotlight_url:
177178
return None
178179

179180
try:

0 commit comments

Comments
 (0)