The Fix
pip install pydantic==1.10.19
Based on closed pydantic/pydantic issue #9523 · 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%.
@@ -5,7 +5,7 @@
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
-content_hash = "sha256:65c1ddf4e0d8613d976f043e92a309a87d133d3424f27e8cab7907f19889efa7"
+content_hash = "sha256:0fa988af1e0b9ae6e18b2a31a32d54aba8db98db5a9428207aa897831e836b82"
def extract_host_and_path_1(url: AnyUrl) -> tuple[str, str]:
if not url.path:
raise Exception()
return url.host, url.path
def extract_host_and_path_2(url: AnyUrl) -> tuple[str, str]:
if not url.host:
raise Exception()
if not url.path:
raise Exception()
return url.host, url.path
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install pydantic==1.10.19\nWhen NOT to use: This fix should not be used if backward compatibility with existing code is required.\n\n
Why This Fix Works in Production
- Trigger: `AnyUrl` requires host for validation but `.host` is typed `None | str`
- Mechanism: The AnyUrl type incorrectly allows None as a host due to typing issues
- Why the fix works: Migrates to subclassing instead of the annotated approach for Pydantic URL types, addressing the typing issue with AnyUrl requiring a host. (first fixed release: 1.10.19).
- 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.11 in real deployments (not just unit tests).
- The AnyUrl type incorrectly allows None as a host due to typing issues
- Production symptom (often without a traceback): `AnyUrl` requires host for validation but `.host` is typed `None | str`
Proof / Evidence
- GitHub issue: #9523
- Fix PR: https://github.com/pydantic/pydantic/pull/10662
- First fixed release: 1.10.19
- 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.64
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“So this is a bit more complicated than anticipated, but I'll fix this with https://github.com/pydantic/pydantic/issues/7353”
“@mfontanaar, Agreed, this is either a bug or the docs are wrong. I think we should probably remote the note in the docs about the…”
“Yeah, I can confirm this is a typing issue. I'll fix this tomorrow.”
“My current understanding of why this is difficult is the following: We support a requires_url constraint on Url types that can be True or False”
Failure Signature (Search String)
- `AnyUrl` requires host for validation but `.host` is typed `None | str`
- raise Exception()
Copy-friendly signature
Failure Signature
-----------------
`AnyUrl` requires host for validation but `.host` is typed `None | str`
raise Exception()
Error Message
Signature-only (no traceback captured)
Error Message
-------------
`AnyUrl` requires host for validation but `.host` is typed `None | str`
raise Exception()
Minimal Reproduction
def extract_host_and_path_1(url: AnyUrl) -> tuple[str, str]:
if not url.path:
raise Exception()
return url.host, url.path
def extract_host_and_path_2(url: AnyUrl) -> tuple[str, str]:
if not url.host:
raise Exception()
if not url.path:
raise Exception()
return url.host, url.path
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Users cannot create valid AnyUrl instances, leading to untestable code paths.
Why It Broke
The AnyUrl type incorrectly allows None as a host due to typing issues
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.19
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/pydantic/pydantic/pull/10662
First fixed release: 1.10.19
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if backward compatibility with existing code is required.
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 |
|---|---|
| 1.10.19 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.