Skip to content

Commit

Permalink
fix(starlette): Fix failed_request_status_codes=[] (#3561)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
szokeasaurusrex committed Sep 24, 2024
1 parent ccdbffb commit 09c6f2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 09c6f2a

Please # to comment.