Skip to content

Commit 98df1bc

Browse files
MichaelGHSegclaude
andcommitted
Fix Retry-After header never parsed on non-2xx responses
requests.Response.__bool__() returns False for non-2xx status codes. The checks `if e.response` and `if response` evaluated to False for 429 responses, so parse_retry_after() was never called and the SDK fell back to normal backoff instead of respecting Retry-After. Changed both checks to explicit `is not None` comparisons. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2474b46 commit 98df1bc

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

segment/analytics/consumer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def pause(self):
7878

7979
def set_rate_limit_state(self, response):
8080
"""Set rate-limit state from a 429 response with a valid Retry-After header."""
81-
retry_after = parse_retry_after(response) if response else None
81+
retry_after = parse_retry_after(response) if response is not None else None
8282
if retry_after is not None:
8383
self.rate_limited_until = time.time() + retry_after
8484
if self.rate_limit_start_time is None:
@@ -257,7 +257,7 @@ def calculate_backoff_delay(attempt):
257257
# to caller (pipeline blocking). Without Retry-After, fall
258258
# through to counted backoff like any other retryable error.
259259
if e.status == 429:
260-
retry_after = parse_retry_after(e.response) if e.response else None
260+
retry_after = parse_retry_after(e.response) if e.response is not None else None
261261
if retry_after is not None:
262262
self.set_rate_limit_state(e.response)
263263
raise

0 commit comments

Comments
 (0)