Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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
repro.py
class URL: def __init__(self, url: URLTypes = "", params: QueryParamTypes = None) -> None: if isinstance(url, str): ... else: self._uri_reference = url._uri_reference
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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”
Issue thread · issue description · source

Failure Signature (Search String)

  • 'URL' object has no attribute '_uri_reference'

Error Message

Stack trace
error.txt
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

repro.py
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.

When NOT to use: This fix should not be used if the URL class is expected to accept non-string types.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

verify
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

VersionStatus
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.