Repository navigation
Conversation
The sync HTTPClient wraps requests.Timeout / requests.ConnectionError as RequestTimeoutError / NetworkError, but AsyncHTTPClient did not wrap anything -- it imported NetworkError and RequestTimeoutError yet never used them, so a timeout or connection failure escaped as a raw asyncio.TimeoutError / aiohttp.ClientConnectionError. Callers catching PaddleOCRAPIError around async calls silently missed these, diverging from the sync contract. Add a _request() async context manager that maps asyncio.TimeoutError -> RequestTimeoutError and aiohttp.ClientConnectionError -> NetworkError, and route all five request sites (submit_url, submit_file, get_job_status, get_batch_status, fetch_jsonl) through it. Add tests/api_client/test_async_http.py covering the connection-refused and timeout paths (uses asyncio.run, no new test dependency). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for your contribution! |
Collaborator
|
Please sign the CLA |
The pre-commit black hook collapses the submit_file request call onto a single line (it fits in 88 chars). Formatting only -- the AST is unchanged from the reviewed commit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Sorry for the churn — I pushed |
Bobholamovic
approved these changes
Jul 22, 2026
Author
|
Gentle ping — approved, CLA signed, style + Python checks green. The |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The synchronous
HTTPClient(_http.py) maps transport failures to the SDK'serror types —
requests.Timeout → RequestTimeoutError,requests.ConnectionError → NetworkError— so callers can rely on the documented contract that everyfailure is a
PaddleOCRAPIErrorsubclass.The asynchronous
AsyncHTTPClient(_async_http.py) did not. It importsNetworkErrorandRequestTimeoutError(lines 28–29) but never used them — aclear sign the wrapping was intended but missing. All five request sites
(
submit_url,submit_file,get_job_status,get_batch_status,fetch_jsonl) issuedaiohttprequests with no transport-error handling.As a result, a timeout or connection failure on an async call escapes as a raw
asyncio.TimeoutError/aiohttp.ClientConnectionErrorinstead of aPaddleOCRAPIError. User code doingexcept PaddleOCRAPIError(orexcept RequestTimeoutError) around async calls silently fails to catch it,diverging from the sync client.
Demonstrated on the current code (server unreachable / slow):
NetworkErroraiohttp.ClientConnectorError(leaks)RequestTimeoutErrorbuiltins.TimeoutError(leaks)Fix
Add a small
_request()async context manager that enters theaiohttprequestand maps
asyncio.TimeoutError → RequestTimeoutErrorandaiohttp.ClientConnectionError → NetworkError(mirroring the sync client), thenroute all five request sites through it. After the fix both scenarios above
raise the SDK error types, matching the sync contract.
Tests
Adds
tests/api_client/test_async_http.pycovering the connection-refused andtimeout paths for both
get_job_statusandfetch_jsonl. The tests drive theasync client with
asyncio.run(...), so they add no new test dependency.Verified the new tests fail on the pre-fix code and pass with the fix.