Repository navigation
fix: honor legacy custom async HTTP clients - #294
Open
mayankbohradev wants to merge 1 commit into
Open
mayankbohradev wants to merge 1 commit into
mayankbohradev wants to merge 1 commit into
Conversation
Keep a reference to the automatic async client so a legacy custom client is selected before that default. Preserve priority for a replacement dedicated client and document the selection order. Add regression and control tests for dispatch, timeouts and errors.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #294 +/- ##
===========================================
+ Coverage 82.66% 97.28% +14.61%
===========================================
Files 4 74 +70
Lines 75 4268 +4193
===========================================
+ Hits 62 4152 +4090
- Misses 13 116 +103 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What changed
Async requests now use an
AsyncHTTPClientassigned toresend.default_http_clientwhen the dedicated async setting still holds the automatic client. A replacement assigned toresend.default_async_http_clientretains priority.The module keeps a private reference to the client created at import time. The dispatcher uses that reference to distinguish the automatic default from a user-supplied client. The README explains the selection order and recommends the dedicated setting for new code.
Why
The original async support documented this configuration:
With
httpxinstalled, module initialization also createsdefault_async_http_client. The dispatcher selected that non-Noneclient before checking the legacy setting. As a result, the request used the automatic client's 30-second timeout instead of the configured 60-second timeout. A custom subclass's request method was also bypassed.I reproduced this on upstream
4ce466ebefore changing the dispatcher. The current dedicated-client configuration already worked and remains the preferred configuration.How it was tested
Emails.send_async,Emails.get_asyncandUsage.get_asynccalls through the real SDK dispatcher and HTTPX client.httpx.MockTransportsupplies the HTTP response. Assertions check the selected client, timeout, request body, authentication and idempotency headers, and returned response headers.HTTPXClient; legacy clients; the automatic default; clearing or restoring the dedicated setting; and missing-client and custom-client error behavior.site-packageswith isolated Python execution. Ten checks passed with the async extra; four passed withouthttpx, including custom async clients and synchronous requests.toxpassed on Python 3.14;tox -e lint,mypy,pypassed on Python 3.9. The four changed files still match the patch after formatting.git diff --checkpassed.Commands for the focused and full checks:
python -m pytest -q tests/async_http_client_selection_test.py tox # Python 3.9: lint, mypy and complete test suite tox -e lint,mypy,py python -m buildThe existing Audiences deprecation warnings remain. Python 3.9 also reports an environment warning because its SSL module uses LibreSSL. Package build warnings concern the existing license classifier and universal-wheel settings.
All HTTP responses in these checks are controlled locally. No request was sent to the live Resend API. The full upstream Python version matrix was not run.
Scope
This change restores legacy async configuration while preserving explicit dedicated-client priority. It does not change the synchronous dispatcher, error mapping, dependency versions or connection lifecycle.