From f58fca84aae85679086d23a9848ac4fcb1df2dcd Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 21 Mar 2025 15:32:26 +0000 Subject: [PATCH 1/4] fix: Always set _spotlight_script The conditional early exit in `SpotlightMiddleware` may cause attribute access errors when trying to check if `_spotlight_script` is set or not. This patch sets it to `None` explicitly and always in the constructor to avoid/fix the issue. --- sentry_sdk/spotlight.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index a783b155a1..70a96ab116 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -86,6 +86,7 @@ class SpotlightMiddleware(MiddlewareMixin): # type: ignore[misc] def __init__(self, get_response): # type: (Self, Callable[..., HttpResponse]) -> None super().__init__(get_response) + _spotlight_script = None import sentry_sdk.api From 6b6ac37acd1499e132956a7d4ab76b5d57b9967b Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 21 Mar 2025 15:37:26 +0000 Subject: [PATCH 2/4] lol --- sentry_sdk/spotlight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index 70a96ab116..12c3df9284 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -86,7 +86,7 @@ class SpotlightMiddleware(MiddlewareMixin): # type: ignore[misc] def __init__(self, get_response): # type: (Self, Callable[..., HttpResponse]) -> None super().__init__(get_response) - _spotlight_script = None + self._spotlight_script = None import sentry_sdk.api From ae2ef7998b0176d49dea97433749500b5b017660 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 21 Mar 2025 16:10:32 +0000 Subject: [PATCH 3/4] lol^2 --- sentry_sdk/spotlight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index 12c3df9284..dad13abcbb 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -82,11 +82,11 @@ def capture_envelope(self, envelope): class SpotlightMiddleware(MiddlewareMixin): # type: ignore[misc] _spotlight_script = None # type: Optional[str] + _spotlight_url = None # type: Optional[str] def __init__(self, get_response): # type: (Self, Callable[..., HttpResponse]) -> None super().__init__(get_response) - self._spotlight_script = None import sentry_sdk.api From cc69ef1ecc61bf3a93d6809a6992cd75577460dc Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 21 Mar 2025 16:13:21 +0000 Subject: [PATCH 4/4] fix type and access errors --- sentry_sdk/spotlight.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index dad13abcbb..c2473b77e9 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -104,7 +104,7 @@ def __init__(self, get_response): @property def spotlight_script(self): # type: (Self) -> Optional[str] - if self._spotlight_script is None: + if self._spotlight_url is not None and self._spotlight_script is None: try: spotlight_js_url = urllib.parse.urljoin( self._spotlight_url, SPOTLIGHT_JS_ENTRY_PATH @@ -174,7 +174,7 @@ def process_response(self, _request, response): def process_exception(self, _request, exception): # type: (Self, HttpRequest, Exception) -> Optional[HttpResponseServerError] - if not settings.DEBUG: + if not settings.DEBUG or not self._spotlight_url: return None try: