fix(client): tolerate older optional aiohttp installations (#3941)
## Summary Fixes #3939. When older aiohttp is installed, importing the optional adapter currently raises `AttributeError` for `aiohttp.SocketTimeoutError`. The SDK catches `ImportError`, so this breaks `import openai` even for applications using only the default HTTPX2 clients. Import the required exception explicitly so the existing unavailable-adapter path handles its absence. No SDK version bounds or new minimum aiohttp version checks are introduced. The `openai[aiohttp]` dependency requirement remains unchanged, and the optional adapter remains unavailable on the older exception surface. This refreshes the minimal import change previously proposed by @marcuswood-oai in #3868, with sync/async regressions and vendor documentation. ## Validation - Reproduced the original bare-import failure using the unmodified v3.18.0 release and actual aiohttp 3.9.3. - Added absent-aiohttp and pre-3.10 subprocess cases. The legacy case failed with the original `AttributeError` before the fix and passed afterward. - Each subprocess exercises synchronous and asynchronous SDK requests through HTTPX2 mock transports, checks the explicit unsupported-adapter error, and verifies legacy HTTPX was not imported. - The regression preserves `aiohttp.client` and earlier exception imports so an unrelated `ModuleNotFoundError` cannot make the old code pass. - Targeted transport suites: 39 passed, one skipped because optional `botocore` is not installed. This includes a real local HTTP request through the supported aiohttp adapter. - Real aiohttp 3.8.6, 3.9.3, 3.10.0, and 3.14.3 fixtures passed default sync/async request probes against this patch. Old versions are test fixtures, not recommended installations or supported aiohttp transports. - Changed tests passed Ruff lint and formatting. Existing repository exclusions for vendored code remain unchanged. ```shell python -m pytest -o addopts= tests/test_httpx2.py tests/test_httpx2_base.py tests/test_httpx2_respx.py tests/test_httpx2_workload.py -q -rs ``` No dependency, generated-baseline, custom-code budget, or workflow changes. Full CI and maintainer review remain required. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Marcus Wood <marcuswood@openai.com> Copilot-Session: 0857d4b0-2459-4f7b-af29-366e05d08090
R
Rana Singh committed
0d91efbe5084c2f572688e8e9a05c0a91c8c0319
Parent: d041d73
Committed by GitHub <noreply@github.com>
on 9/22/2026, 8:59:16 PM