Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -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,
repro.py
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
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.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).
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 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

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…”
@sydney-runkle · 2024-07-01 · confirmation · source
“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…”
@mudravrik · 2024-07-01 · source

Failure Signature (Search String)

  • TypeError: create_model() missing 1 required positional argument: 'model_name'

Error Message

Stack trace
error.txt
Error Message ------------- TypeError: create_model() missing 1 required positional argument: 'model_name'

Minimal Reproduction

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

When NOT to use: This fix is not applicable if the code relies on the previous argument naming convention.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the code relies on the previous argument naming convention.

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