Add retry handling for 429 and transient errors#23
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurable retry/backoff support to the SDK’s request layer so transient failures (HTTP 429 / 5xx / connection errors) don’t immediately surface as user-visible errors, and introduces a dedicated RateLimitError to let callers handle rate limiting explicitly (closes #15).
Changes:
- Introduces
RateLimitErrorand exports it from the package. - Adds
max_retries/backoff_baseconfiguration toAtomicClientand propagates it into all resource clients. - Implements retry handling (429 w/
Retry-After, 5xx exponential backoff w/ jitter, and request exceptions) plus retry logging inResourceClient.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
atomic_sdk/exceptions.py |
Adds RateLimitError with retry_after payload. |
atomic_sdk/client.py |
Adds retry configuration to AtomicClient and forwards it to resource clients. |
atomic_sdk/api/base.py |
Implements retry/backoff logic in _request and _get_raw, plus Retry-After parsing and retry logging. |
atomic_sdk/__init__.py |
Exposes RateLimitError as part of the public API. |
Comments suppressed due to low confidence (1)
atomic_sdk/api/base.py:34
ResourceClient.__init__docstring lists onlysession,base_url, andclient_id_or_name, but the signature now includesmax_retriesandbackoff_base. Update the docstring so callers (and generated docs) reflect the new behavior/configuration.
def __init__(
self,
session: requests.Session,
base_url: str,
client_id_or_name: str,
max_retries: int = 3,
backoff_base: float = 0.5,
):
"""
Initializes the ResourceClient.
Args:
session: A requests.Session object configured with authentication.
base_url: The base URL for the Atomic API.
client_id_or_name: The client's identifier (name or ID).
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Validated retry handling locally against the issue #15 acceptance criteria. The focused mocked tests cover Input python -m pytest tests/test_retries.py -qOutput The warning is pre-existing in |
|
Validated again and tests Passed Successfully. ====================================================================== warnings summary ======================================================================
atomic_sdk/models.py:132
/workspace/release_20260121_175120/wp-cloud-atomic-sdk/atomic_sdk/models.py:132: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.13/migration/
@validator("complete", pre=True)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
15 passed, 1 warning in 0.11sTest File : test_retries.py |
Closes: #15