The Fix
pip install pydantic==2.7.2
Based on closed pydantic/pydantic issue #9810 · 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%.
@@ -7,12 +7,26 @@
import warnings
from copy import copy, deepcopy
-from typing import Any, ClassVar, Dict, Generator, Literal, Set, Tuple, TypeVar, Union
+from typing import (
+ TYPE_CHECKING,
def inject_default_from_instance(instance_w_defaults: BaseModel) -> Type[BaseModel]:
model_w_defaults = create_model(
__model_name=instance_w_defaults.__repr_name__() + "WithDefaults",
__base__=type(instance_w_defaults),
**{
k: (
instance_w_defaults.model_fields[k].annotation,
FieldInfo.merge_field_infos(
instance_w_defaults.model_fields[k],
default=getattr(instance_w_defaults, k)
)
)
for k in instance_w_defaults.model_fields.keys()
}
)
return model_w_defaults
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.2\nWhen NOT to use: This fix is not applicable if the code relies on the previous argument naming convention.\n\n
Why This Fix Works in Production
- Trigger: TypeError: create_model() missing 1 required positional argument: 'model_name'
- Mechanism: The argument name for `create_model()` was changed from `__model_name` to `model_name`, causing compatibility issues
- Why the fix works: The argument name for `create_model()` was changed from `__model_name` to `model_name`, which caused compatibility issues for users relying on the previous naming convention. (first fixed release: 2.7.2).
- 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 argument name for `create_model()` was changed from `__model_name` to `model_name`, causing compatibility issues
- Surfaces as: TypeError: create_model() missing 1 required positional argument: 'model_name'
Proof / Evidence
- GitHub issue: #9810
- Fix PR: https://github.com/pydantic/pydantic/pull/9479
- First fixed release: 2.7.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.59
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@mudravrik, > After some reading on topic I got to this part of PEP-570 explaining, that __model_name is a naming convetion meaning, that it is…”
“After some reading on topic I got to this part of PEP-570 explaining, that __model_name is a naming convetion meaning, that it is positional-only argument…”
Failure Signature (Search String)
- TypeError: create_model() missing 1 required positional argument: 'model_name'
Error Message
Stack trace
Error Message
-------------
TypeError: create_model() missing 1 required positional argument: 'model_name'
Minimal Reproduction
def inject_default_from_instance(instance_w_defaults: BaseModel) -> Type[BaseModel]:
model_w_defaults = create_model(
__model_name=instance_w_defaults.__repr_name__() + "WithDefaults",
__base__=type(instance_w_defaults),
**{
k: (
instance_w_defaults.model_fields[k].annotation,
FieldInfo.merge_field_infos(
instance_w_defaults.model_fields[k],
default=getattr(instance_w_defaults, k)
)
)
for k in instance_w_defaults.model_fields.keys()
}
)
return model_w_defaults
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Pipelines failed during tests with TypeError due to the argument name change.
Why It Broke
The argument name for `create_model()` was changed from `__model_name` to `model_name`, causing compatibility issues
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.7.2
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/9479
First fixed release: 2.7.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the code relies on the previous argument naming convention.
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.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.