Jump to solution
Verify

The Fix

pip install pydantic==2.11.0

Based on closed pydantic/pydantic issue #11689 · 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
@@ -17,7 +17,7 @@ from pydantic.errors import PydanticUserError -from . import _typing_extra +from . import _generics, _typing_extra from ._config import ConfigWrapper
repro.py
# file models/company.py from models.employee import * # noqa: F403 from pydantic import BaseModel class Company(BaseModel): name: str employees: list['Employee'] # noqa: F405 # file models/employee.py from models.company import * # noqa: F403 from pydantic import BaseModel class Employee(BaseModel): name: str company: 'Company' # noqa: F405 # main.py import inspect import pkgutil from importlib import import_module from pathlib import Path from pydantic import BaseModel def main(): loaded_module = import_module('models') package_path = Path(loaded_module.__file__).parent for _, name, is_pkg in pkgutil.walk_packages([str(package_path)]): full_name = f"models.{name}" module = import_module(full_name) for _, cls in inspect.getmembers(module, inspect.isclass): if issubclass(cls, BaseModel) and cls is not BaseModel: cls.model_rebuild() if __name__ == '__main__': main()
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.11.0\nWhen NOT to use: Do not use this fix if your models rely on dynamic imports that may not be fully initialized.\n\n

Why This Fix Works in Production

  • Trigger: ImportError: cannot import name 'Company' from partially initialized module 'testm.company'
  • Mechanism: The issue arises from changes in annotations evaluation, causing incomplete model references
  • Why the fix works: Addresses issues with model field collection in Pydantic, particularly regarding forward references. (first fixed release: 2.11.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.12 in real deployments (not just unit tests).
  • The issue arises from changes in annotations evaluation, causing incomplete model references
  • Surfaces as: ImportError: cannot import name 'Company' from partially initialized module 'testm.company'

Proof / Evidence

Discussion

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

“Thanks @Viicos of your answer! I've solved it just by splitting to two loops in main.py: - the first one just imports all models -…”
@emiltem · 2025-04-04 · source
“This is due to a change in https://github.com/pydantic/pydantic/pull/11388 which cleaned up parts of the annotations evaluation”
@Viicos · 2025-04-04 · confirmation · source

Failure Signature (Search String)

  • ImportError: cannot import name 'Company' from partially initialized module 'testm.company'

Error Message

Stack trace
error.txt
Error Message ------------- ImportError: cannot import name 'Company' from partially initialized module 'testm.company'

Minimal Reproduction

repro.py
# file models/company.py from models.employee import * # noqa: F403 from pydantic import BaseModel class Company(BaseModel): name: str employees: list['Employee'] # noqa: F405 # file models/employee.py from models.company import * # noqa: F403 from pydantic import BaseModel class Employee(BaseModel): name: str company: 'Company' # noqa: F405 # main.py import inspect import pkgutil from importlib import import_module from pathlib import Path from pydantic import BaseModel def main(): loaded_module = import_module('models') package_path = Path(loaded_module.__file__).parent for _, name, is_pkg in pkgutil.walk_packages([str(package_path)]): full_name = f"models.{name}" module = import_module(full_name) for _, cls in inspect.getmembers(module, inspect.isclass): if issubclass(cls, BaseModel) and cls is not BaseModel: cls.model_rebuild() if __name__ == '__main__': main()

Environment

  • Python: 3.12
  • Pydantic: 2.11.0

What Broke

Models fail to build correctly, leading to runtime errors and application crashes.

Why It Broke

The issue arises from changes in annotations evaluation, causing incomplete model references

Fix Options (Details)

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

pip install pydantic==2.11.0

When NOT to use: Do not use this fix if your models rely on dynamic imports that may not be fully initialized.

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

First fixed release: 2.11.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

  • Do not use this fix if your models rely on dynamic imports that may not be fully initialized.

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

Related Issues

No related fixes found.

Sources

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