Skip to content

fix: surface final transport errors after mixed retries - #1

Open
omerbek wants to merge 1 commit into
OpenCMC:mainfrom
omerbek:fix/final-retry-error
Open

omerbek wants to merge 1 commit into
OpenCMC:mainfrom
omerbek:fix/final-retry-error

Conversation

@omerbek

@omerbek omerbek commented Nov 8, 2026

Copy link
Copy Markdown

Summary

  • Clear a previous retryable HTTP response when a later attempt fails at the transport level, in both sync and async retry transports.
  • Add six zero-delay mixed-outcome regressions and document the final-attempt behavior.

Problem / root cause

RetryTransport and AsyncRetryTransport retained last_response after subsequent network exceptions, then returned it before considering last_error when retries were exhausted. A 503 followed by two connection failures therefore surfaced InternalServerError/503 instead of the documented APIConnectionError; the same issue hid final timeouts.

Change

The production fix is one assignment in each catch block (last_response = None). Existing retry statuses, delays, counts, and error conversion stay unchanged. Tests cover 503 → ConnectError → ConnectError, 503 → ReadTimeout → ReadTimeout, and the reverse ConnectError → 503 → 502, in both sync and async clients. Generated code and exported signatures are unchanged.

Testing

  • Python 3.11.5; httpx 0.28.1; real current source, not a retry reimplementation.
  • python -m pytest -q: 78 passed.
  • python -m ruff check coinmarketcap tests: all checks passed.
  • Standalone offline smoke used the public CoinMarketCap(...).cryptocurrency.quotes_latest and async_quotes_latest methods, real generated endpoint/client, retry transports, and typed-error wrappers. Only the innermost HTTP transport was replaced with httpx.MockTransport; no production requests or real API key.
  • Before: all four sync/async connection/timeout sequences raised stale InternalServerError/503 after three requests.
  • After: connection sequences raised APIConnectionError, timeout sequences raised APITimeoutError; each preserved the exact final httpx exception in .cause, with three requests.
  • Full supported-Python CI matrix, mypy, and packaging builds were not run locally. Local runtime/test tooling was deliberately lightweight; no unrelated configuration or generated code changes.

Risk / compatibility

Only mixed HTTP/transport retry exhaustion changes. A final HTTP response still wins over an earlier transport error; pure HTTP, pure network, success and retry-count behavior are covered by the existing suite. This is the Python counterpart of the independently published TypeScript fix in OpenCMC/coinmarketcap-api-typescript#1; the TS PR is not changed here.

AI assistance was used for investigation, implementation, and tests. All claimed local results were actually executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant