Skip to content

Commit 7fa7a5d

Browse files
lesnik512claude
andcommitted
fix(resilience): replace bare assert with -O-safe guard + cross-ref note
- Retry.__call__: assert last_exc is not None is stripped by python -O, which would convert the structural invariant into an AttributeError ("NoneType has no attribute add_note") in optimized runtimes. Replace with an if guard that raises AssertionError unconditionally. - test_budget_exhausted_raises_retry_budget_exhausted_error: add a NOTE warning Task 11 not to duplicate this test (it lives in Task 7 only because the budget gate's RetryBudgetExhaustedError branch needs coverage from the Retry-loop side). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 555bc6c commit 7fa7a5d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/httpware/middleware/resilience/retry.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ async def __call__(self, request: httpx2.Request, next: Next) -> httpx2.Response
8989

9090
# ---- retryable failure path
9191
if is_last:
92-
assert last_exc is not None
92+
if last_exc is None: # pragma: no cover — structural invariant from except branch
93+
msg = "Retry: last_exc unset on final attempt — unreachable"
94+
raise AssertionError(msg)
9395
last_exc.add_note(f"httpware: gave up after {attempt + 1} attempts")
9496
raise last_exc
9597

‎tests/test_retry.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def test_max_attempts_zero_rejected() -> None:
139139

140140

141141
async def test_budget_exhausted_raises_retry_budget_exhausted_error() -> None:
142+
# NOTE: lives here for coverage of the Retry loop's budget-exhaustion branch.
143+
# Task 11 adds the broader budget-gate + sharing tests (carry-through behavior,
144+
# last_response / last_exception field population). Do NOT duplicate this test.
142145
sleeper = _SleepRecorder()
143146
handler = _ResponseSequence([HTTPStatus.SERVICE_UNAVAILABLE, HTTPStatus.SERVICE_UNAVAILABLE])
144147
# Budget with zero tolerance: percent_can_retry=0.0, min_retries_per_sec=0.0 → ceiling=0

0 commit comments

Comments
 (0)