Skip to content

fix(sdk): backoff fork, async retries and User-Agent - #72

Open
sbscully wants to merge 6 commits into
masterfrom
fix/sdk/backoff-and-async-requests
Open

sbscully wants to merge 6 commits into
masterfrom
fix/sdk/backoff-and-async-requests

Conversation

@sbscully

@sbscully sbscully commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Replace the unmaintained backoff package with the maintained python-backoff fork, which removes the asyncio.iscoroutinefunction DeprecationWarning on Python 3.14/3.15.

Retry async requests on transient failures (UnknownError, aiohttp.ClientError, asyncio.TimeoutError), matching the retries the sync path already performs.

Send the OpenCage User-Agent on async requests, which previously sent none. Also correct the sync request's User-Agent, which was labelled as the aiohttp client even though it is made with requests.

Disable backoff retry logging on both paths, since its default handlers log the exception text, which embeds the request URL including the API key.

python-backoff provides the same backoff module but fixes the asyncio.iscoroutinefunction DeprecationWarning on Python 3.14/3.15.
Async requests omitted the User-Agent header entirely. Also label the sync session request as the requests client rather than aiohttp.
The sync request retries via backoff but the async request did not. Apply the same backoff.on_exception to _opencage_async_request, retrying on UnknownError, aiohttp.ClientError and asyncio.TimeoutError. NotAuthorized, Forbidden, RateLimitExceeded and SSLError remain terminal, as on the sync path.
@sbscully sbscully self-assigned this Nov 28, 2026
Comment thread opencage/geocoder.py Resolved
Comment thread opencage/geocoder.py Resolved
Comment thread test/test_error_network.py Resolved
Comment thread opencage/geocoder.py Resolved
Comment thread opencage/geocoder.py Resolved
Comment thread test/test_error_network.py Resolved
Build the async retry exception tuple so importing opencage.geocoder works when aiohttp is absent, which the import guard intends to support but the decorator previously broke.

Add session-based sync and async User-Agent tests, and cover the UnknownError and asyncio.TimeoutError retry branches alongside the existing client-error case.
backoff's default on_backoff/on_giveup handlers log the exception, which embeds the request URL including key=... . Set logger=None on both the sync and async decorators so those lines are not emitted; raised errors stay sanitized via _sanetize_exception_message. Add tests asserting the key never reaches the logs.
Cover NotAuthorizedError, ForbiddenError, RateLimitExceededError and SSLError by asserting the request is attempted exactly once, so a broadened retry tuple would be caught.
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