fix(provider): adapt anthropic source to httpx2 rename in anthropic 1.0.0 - #9791
Merged
Merged
Conversation
….0.0 anthropic 1.0.0 renamed the bundled ``_base_client.httpx`` module to ``_base_client.httpx2``. The previous ``getattr(_base_client, "httpx", httpx)`` fallback silently reverted to the global httpx import, which can break the SDK's isinstance validation when a proxy client is used. Resolve the SDK's own module in version-agnostic order (httpx → httpx2 → global) and update the corresponding unit test to assert against the same resolution.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_anthropic_kimi_code_provider.py" line_range="140-144" />
<code_context>
+ # anthropic <1.0.0 exposes the bundled httpx as ``_base_client.httpx``;
+ # 1.0.0+ renamed it to ``_base_client.httpx2``. Resolve the SDK's own module
+ # the same way the production code does so the assertion stays version-agnostic.
+ expected_httpx_module = getattr(
+ anthropic_base_client,
+ "httpx",
+ getattr(anthropic_base_client, "httpx2", None),
+ )
+
assert captured["provider_label"] == "Anthropic"
</code_context>
<issue_to_address>
**issue (testing):** When `_base_client` imports successfully but exposes neither `httpx` nor `httpx2`, production resolves the global `httpx` module while the test expects `None`, so the assertion fails even though the implementation follows the documented fallback chain.
**Triggers:** When an installed Anthropic SDK lacks both bundled module attributes.
**Suggested fix:** Use `getattr(anthropic_base_client, "httpx2", httpx)` in the test fallback, matching production.
```suggestion
expected_httpx_module = getattr(
anthropic_base_client,
"httpx",
getattr(anthropic_base_client, "httpx2", httpx),
)
```
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/test_anthropic_kimi_code_provider.py:144
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+140
to
+144
| expected_httpx_module = getattr( | ||
| anthropic_base_client, | ||
| "httpx", | ||
| getattr(anthropic_base_client, "httpx2", None), | ||
| ) |
Contributor
There was a problem hiding this comment.
issue (testing): When _base_client imports successfully but exposes neither httpx nor httpx2, production resolves the global httpx module while the test expects None, so the assertion fails even though the implementation follows the documented fallback chain.
Triggers: When an installed Anthropic SDK lacks both bundled module attributes.
Suggested fix: Use getattr(anthropic_base_client, "httpx2", httpx) in the test fallback, matching production.
Suggested change
| expected_httpx_module = getattr( | |
| anthropic_base_client, | |
| "httpx", | |
| getattr(anthropic_base_client, "httpx2", None), | |
| ) | |
| expected_httpx_module = getattr( | |
| anthropic_base_client, | |
| "httpx", | |
| getattr(anthropic_base_client, "httpx2", httpx), | |
| ) |
5 tasks
BegoniaHe
pushed a commit
to Xero-Team/AstrBot
that referenced
this pull request
Aug 24, 2026
….0.0 (AstrBotDevs#9791) Upstream-Commit: c87b773 Upstream-Author: Ruochen Pan <badbatch0x01@gmail.com> Upstream-PR: AstrBotDevs#9791 Sync-Disposition: adapt Fork-Adaptation: Apply the version-agnostic httpx/httpx2 resolution on the current Anthropic source and the relocated unit test, keeping the fork proxy-client capture shape. Tested: uv run pytest tests/unit/provider/test_anthropic_kimi_code_provider.py -q
BegoniaHe
added a commit
to Xero-Team/AstrBot
that referenced
this pull request
Aug 24, 2026
Record adapted AstrBotDevs#9791 and AstrBotDevs#9752 through c6a14e0.
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.
anthropic 1.0.0 renamed the bundled
_base_client.httpxmodule to_base_client.httpx2. The previousgetattr(_base_client, "httpx", httpx)fallback silently reverted to the global httpx import, which can break the SDK's isinstance validation when a proxy client is used. Resolve the SDK's own module in version-agnostic order (httpx → httpx2 → global) and update the corresponding unit test to assert against the same resolution.Modifications / 改动点
astrbot/core/provider/sources/anthropic_source.py_create_http_client()previously resolved the SDK's bundled httpx viagetattr(_base_client, "httpx", httpx). anthropic 1.0.0 renamed that attribute to_base_client.httpx2, so the old code silently fell back to the globalhttpximport and could fail the SDK's ownisinstancevalidation when a proxy client is used._base_client.httpx→_base_client.httpx2→ globalhttpx.tests/test_anthropic_kimi_code_provider.pytest_create_http_client_uses_anthropic_httpx_modulehardcodedanthropic_base_client.httpx, which raisesAttributeErroron anthropic 1.0.0 (Did you mean: 'httpx2'?). The assertion now derives the expected module using the same fallback chain as the production code, so it passes on both anthropic <1.0.0 and >=1.0.0.This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Support the Anthropic SDK’s httpx module rename while maintaining compatibility with older releases.
Bug Fixes:
Tests: