Jump to solution
Verify

The Fix

pip install pydantic==2.5.0

Based on closed pydantic/pydantic issue #8745 · 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
@@ -89,6 +89,7 @@ BASEMODEL_FULLNAME = 'pydantic.main.BaseModel' BASESETTINGS_FULLNAME = 'pydantic_settings.main.BaseSettings' +ROOT_MODEL_FULLNAME = 'pydantic.root_model.RootModel' MODEL_METACLASS_FULLNAME = 'pydantic._internal._model_construction.ModelMetaclass' FIELD_FULLNAME = 'pydantic.fields.Field'
repro.py
from pydantic import RootModel SimpleID = RootModel[str] class FancyID(RootModel[str]): def __str__(self) -> str: return self.root class HackyID(RootModel[str]): def __init__(self, root: str): super().__init__(root=root) def __str__(self) -> str: return self.root # from https://docs.pydantic.dev/2.5/concepts/models/#rootmodel-and-custom-root-types # "The root value can be passed to the model __init__ or model_validate via the first and only argument." foo = SimpleID('foo') bar = FancyID('bar') # Expected 0 positional arguments Pylance(reportGeneralTypeIssues) hack = HackyID('hack') print(foo) print(bar) print(hack) assert str(bar) == 'bar' # works just fine assert str(hack) == 'hack' bar = FancyID.model_validate('bar') # no type errors
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.5.0\nWhen NOT to use: This fix is not applicable for versions prior to 2.6.\n\n

Why This Fix Works in Production

  • Trigger: Type error on initialization of classes derived from RootModel
  • Mechanism: `mypy` no longer errors when a subclass of `RootModel` is instantiated without a `root` keyword argument.
  • Why the fix works: `mypy` no longer errors when a subclass of `RootModel` is instantiated without a `root` keyword argument. (first fixed release: 2.5.0).
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).
  • Production symptom (often without a traceback): Type error on initialization of classes derived from RootModel

Proof / Evidence

Discussion

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

“@WarpedPixel you are still on 2.5.x, where a positional argument to a RootModel was not allowed”
@Viicos · 2024-02-06 · source
“@WarpedPixel, Thanks for reporting this”
@sydney-runkle · 2024-02-06 · source
“You are correct of course. Just verified with 2.6.1 and it works as expected.”
@WarpedPixel · 2024-02-06 · source

Failure Signature (Search String)

  • Type error on initialization of classes derived from RootModel
  • Note that the code works in all cases, however the type system (Pylance in this case) does not understand it correctly. Moreover, workarounds like the one in `HackyID` below, or
Copy-friendly signature
signature.txt
Failure Signature ----------------- Type error on initialization of classes derived from RootModel Note that the code works in all cases, however the type system (Pylance in this case) does not understand it correctly. Moreover, workarounds like the one in `HackyID` below, or only initializing `FancyID` with `model_validate()` also work.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Type error on initialization of classes derived from RootModel Note that the code works in all cases, however the type system (Pylance in this case) does not understand it correctly. Moreover, workarounds like the one in `HackyID` below, or only initializing `FancyID` with `model_validate()` also work.

Minimal Reproduction

repro.py
from pydantic import RootModel SimpleID = RootModel[str] class FancyID(RootModel[str]): def __str__(self) -> str: return self.root class HackyID(RootModel[str]): def __init__(self, root: str): super().__init__(root=root) def __str__(self) -> str: return self.root # from https://docs.pydantic.dev/2.5/concepts/models/#rootmodel-and-custom-root-types # "The root value can be passed to the model __init__ or model_validate via the first and only argument." foo = SimpleID('foo') bar = FancyID('bar') # Expected 0 positional arguments Pylance(reportGeneralTypeIssues) hack = HackyID('hack') print(foo) print(bar) print(hack) assert str(bar) == 'bar' # works just fine assert str(hack) == 'hack' bar = FancyID.model_validate('bar') # no type errors

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Users experience type errors when initializing RootModel subclasses with positional arguments.

Fix Options (Details)

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

pip install pydantic==2.5.0

When NOT to use: This fix is not applicable for versions prior to 2.6.

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

First fixed release: 2.5.0

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 for versions prior to 2.6.

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

Related Issues

No related fixes found.

Sources

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