The Fix
pip install pydantic==2.7.1
Based on closed pydantic/pydantic issue #9253 · 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%.
@@ -2037,13 +2037,13 @@ def encode_default(self, dft: Any) -> Any:
The encoded default value.
"""
- from .type_adapter import TypeAdapter
+ from .type_adapter import TypeAdapter, _type_has_config
import dataclasses
from pydantic import BaseModel
@dataclasses.dataclass
class Parent:
name: str
class Child(BaseModel):
parent: Parent = Parent(name="unknown parent")
name: str
if __name__ == "__main__":
model_schema = Child.model_json_schema()
print(model_schema)
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==2.7.1\nWhen NOT to use: This fix should not be applied if the model's config is intended to be overridden.\n\n
Why This Fix Works in Production
- Trigger: pydantic.errors.PydanticUserError: Cannot use `config` when the type is a BaseModel, dataclass or TypedDict. These types can have their own config and setting…
- Mechanism: The config handling for models with fields defaulting to Pydantic types was incorrectly implemented
- Why the fix works: Fixes an issue where generating the JSON schema for a model with a field defaulting to a Pydantic type would fail due to config handling. (first fixed release: 2.7.1).
- 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
- The config handling for models with fields defaulting to Pydantic types was incorrectly implemented
- Surfaces as: pydantic.errors.PydanticUserError: Cannot use `config` when the type is a BaseModel, dataclass or TypedDict. These types can have their own config and setting the config via the…
Proof / Evidence
- GitHub issue: #9253
- Fix PR: https://github.com/pydantic/pydantic/pull/9287
- First fixed release: 2.7.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.59
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.7.1
- Mode: fixed_only
- Outcome: ok
Logs
{'$defs': {'Parent': {'properties': {'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name'], 'title': 'Parent', 'type': 'object'}}, 'properties': {'parent': {'allOf': [{'$ref': '#/$defs/Parent'}], 'default': {'name': 'unknown parent'}}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name'], 'title': 'Child', 'type': 'object'}
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@Viicos, Ah yep, thanks for tracking down the issue”
“Relevant code: https://github.com/pydantic/pydantic/blob/b844ea7ae652b88fd002ef040d606ae3262c1010/pydantic/json_schema.py#L2042-L2048 This could be fixed in two ways: - Allow TypeAdapter to take types that supports config (i.e”
“@NeevCohen, Awesome! Excited to work with you on this. Are you suggesting the comprehensive wiring? I suppose as a temporary fix, we could also just…”
“@sydney-runkle I'm not so sure what the required changes in core would be”
Failure Signature (Search String)
- pydantic.errors.PydanticUserError: Cannot use `config` when the type is a BaseModel, dataclass or TypedDict. These types can have their own config and setting the config via the
Error Message
Stack trace
Error Message
-------------
pydantic.errors.PydanticUserError: Cannot use `config` when the type is a BaseModel, dataclass or TypedDict. These types can have their own config and setting the config via the `config` parameter to TypeAdapter will not override it, thus the `config` you passed to TypeAdapter becomes meaningless, which is probably not what you want.
Minimal Reproduction
import dataclasses
from pydantic import BaseModel
@dataclasses.dataclass
class Parent:
name: str
class Child(BaseModel):
parent: Parent = Parent(name="unknown parent")
name: str
if __name__ == "__main__":
model_schema = Child.model_json_schema()
print(model_schema)
Environment
- Pydantic: 2
What Broke
The application crashes when generating JSON schema for models with specific field types.
Why It Broke
The config handling for models with fields defaulting to Pydantic types was incorrectly implemented
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.7.1
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/9287
First fixed release: 2.7.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the model's config is intended to be overridden.
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 |
|---|---|
| 2.7.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.