From 09c6f2a898e9e43378d9598f1938412c512ce48b Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Tue, 24 Sep 2024 12:48:13 +0200 Subject: [PATCH] fix(starlette): Fix `failed_request_status_codes=[]` (#3561) Passing an empty list for `failed_request_status_codes` should result in no status codes resulting in a Sentry error. However, right now, setting `failed_request_status_codes=[]` instead yields the default `failed_request_status_codes` of `range(500, 599)`. This change fixes the incorrect behavior and adds tests to verify the fix. --- sentry_sdk/integrations/starlette.py | 8 +++++--- tests/integrations/starlette/test_starlette.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index fb18bc52e9..6da99b28ae 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -88,9 +88,11 @@ def __init__( ) self.transaction_style = transaction_style self.middleware_spans = middleware_spans - self.failed_request_status_codes = failed_request_status_codes or [ - range(500, 599) - ] + self.failed_request_status_codes = ( + [range(500, 599)] + if failed_request_status_codes is None + else failed_request_status_codes + ) # type: list[HttpStatusCodeRange] @staticmethod def setup_once(): diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index d9dca1669c..59be73dc12 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -1149,6 +1149,7 @@ def test_span_origin(sentry_init, capture_events): ([range(400, 403), 500, 501], 405, False), ([range(400, 403), 500, 501], 501, True), ([range(400, 403), 500, 501], 503, False), + ([], 500, False), ], ) """Test cases for configurable status codes.