The Fix
Upgrade to version 0.15.0 or later.
Based on closed encode/httpx issue #1258 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -71,8 +71,12 @@ def __init__(self, url: URLTypes = "", params: QueryParamTypes = None) -> None:
# removes any leading `../` portion.
self._uri_reference = self._uri_reference.normalize()
- else:
+ elif isinstance(url, URL):
self._uri_reference = url._uri_reference
class URL:
def __init__(self, url: URLTypes = "", params: QueryParamTypes = None) -> None:
if isinstance(url, str):
...
else:
self._uri_reference = url._uri_reference
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.15.0 or later.\nWhen NOT to use: This fix should not be used if the URL class is expected to accept non-string types.\n\n
Why This Fix Works in Production
- Trigger: 'URL' object has no attribute '_uri_reference'
- Mechanism: The URL class did not properly check for valid URL types, leading to misleading attribute errors
- Why the fix works: Raises a proper type error when an invalid URL type is passed to the URL class, addressing the issue of confusing error messages. (first fixed release: 0.15.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- The URL class did not properly check for valid URL types, leading to misleading attribute errors
- Surfaces as: 'URL' object has no attribute '_uri_reference'
Proof / Evidence
- GitHub issue: #1258
- Fix PR: https://github.com/encode/httpx/pull/1259
- First fixed release: 0.15.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.50
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“https://github.com/encode/httpx/blob/642aabdac093cf9798f4881cbdd8b39bd3398bb5/httpx/_models.py#L74 Say, for example, we're using a Starlette API which features a URL type: https://github.com/encode/starlette/blob/c566fc6c819f0d565f8cff43235”
Failure Signature (Search String)
- 'URL' object has no attribute '_uri_reference'
Error Message
Stack trace
Error Message
-------------
'URL' object has no attribute '_uri_reference'
Traceback (most recent call last):
...
File <redacted>, line 27, in <redacted>
async with AsyncClient(base_url=settings.service_baselink) as client:
File "<redacted>/lib/python3.7/site-packages/httpx/_client.py", line 1125, in __init__
trust_env=trust_env,
File "<redacted>/lib/python3.7/site-packages/httpx/_client.py", line 72, in __init__
self._base_url = self._enforce_trailing_slash(URL(base_url))
File "<redacted>/lib/python3.7/site-packages/httpx/_models.py", line 74, in __init__
self._uri_reference = url._uri_reference
AttributeError: 'URL' object has no attribute '_uri_reference'
Minimal Reproduction
class URL:
def __init__(self, url: URLTypes = "", params: QueryParamTypes = None) -> None:
if isinstance(url, str):
...
else:
self._uri_reference = url._uri_reference
Environment
- Python: 3.7
What Broke
Users experienced confusing attribute errors when passing invalid URL types to the URL class.
Why It Broke
The URL class did not properly check for valid URL types, leading to misleading attribute errors
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.15.0 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/encode/httpx/pull/1259
First fixed release: 0.15.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the URL class is expected to accept non-string types.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.15.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.