Jump to solution
Verify

The Fix

pip install pydantic==2.10.2

Based on closed pydantic/pydantic issue #10965 · 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
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, ClassVar -from pydantic_core import MultiHostHost, PydanticCustomError, core_schema +from pydantic_core import MultiHostHost, PydanticCustomError, SchemaSerializer, core_schema from pydantic_core import MultiHostUrl as _CoreMultiHostUrl
repro.py
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, model_serializer from enum import Enum class NewBaseModel(BaseModel): model_config = ConfigDict(extra="forbid") @model_serializer def serialize_model(self) -> dict: data = {} for field_name, field_value in self: data[field_name] = field_value if isinstance(field_value, Enum): data[field_name] = field_value.name return data class Test(NewBaseModel): url: AnyHttpUrl t = Test(url="http://example.com") t.model_dump_json()
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==2.10.2\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n

Why This Fix Works in Production

  • Trigger: return self.__pydantic_serializer__.to_json(
  • Mechanism: Fixed serialization issues with custom model serializers in Pydantic 2.10.1, allowing models to be dumped to JSON correctly.
  • Why the fix works: Fixed serialization issues with custom model serializers in Pydantic 2.10.1, allowing models to be dumped to JSON correctly. (first fixed release: 2.10.2).
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.8 in real deployments (not just unit tests).
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Verified Execution

We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.

  • Status: PASS
  • Ran: 2026-02-11T16:52:29Z
  • Package: pydantic
  • Fixed: 2.10.2
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Hi! Thanks for the question. This was fixed via https://github.com/pydantic/pydantic/pull/10947 and will be fixed in v2.10.2 this afternoon!”
@sydney-runkle · 2024-11-25 · confirmation · source
“I am still getting the same error after I re-ran my unit tests for v2.10.1”
@rashmi-asml · 2024-11-26 · source

Failure Signature (Search String)

  • return self.__pydantic_serializer__.to_json(

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "<stdin>", line 1, in <module> File "CENSORED/.venv/lib/python3.8/site-packages/pydantic/main.py", line 477, in model_dump_json return self.__pydantic_serializer__.to_json( pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.networks.AnyHttpUrl'>

Minimal Reproduction

repro.py
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, model_serializer from enum import Enum class NewBaseModel(BaseModel): model_config = ConfigDict(extra="forbid") @model_serializer def serialize_model(self) -> dict: data = {} for field_name, field_value in self: data[field_name] = field_value if isinstance(field_value, Enum): data[field_name] = field_value.name return data class Test(NewBaseModel): url: AnyHttpUrl t = Test(url="http://example.com") t.model_dump_json()

Environment

  • Python: 3.8
  • Pydantic: 2

What Broke

Models could not be dumped to JSON, leading to serialization errors in production.

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.10.2

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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/10947

First fixed release: 2.10.2

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

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

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
2.10.2 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.