Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -5,7 +5,7 @@ strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:65c1ddf4e0d8613d976f043e92a309a87d133d3424f27e8cab7907f19889efa7" +content_hash = "sha256:0fa988af1e0b9ae6e18b2a31a32d54aba8db98db5a9428207aa897831e836b82"
repro.py
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
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\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).
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.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

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”
@sydney-runkle · 2024-06-19 · source
“@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…”
@sydney-runkle · 2024-06-03 · source
“Yeah, I can confirm this is a typing issue. I'll fix this tomorrow.”
@sydney-runkle · 2024-06-12 · source
“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”
@sydney-runkle · 2024-10-18 · source

Failure Signature (Search String)

  • `AnyUrl` requires host for validation but `.host` is typed `None | str`
  • raise Exception()
Copy-friendly signature
signature.txt
Failure Signature ----------------- `AnyUrl` requires host for validation but `.host` is typed `None | str` raise Exception()

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- `AnyUrl` requires host for validation but `.host` is typed `None | str` raise Exception()

Minimal Reproduction

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

When NOT to use: This fix should not be used if backward compatibility with existing code is required.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if backward compatibility with existing code is required.

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