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%.
@@ -17,7 +17,7 @@
from pydantic.errors import PydanticUserError
-from . import _typing_extra
+from . import _generics, _typing_extra
from ._config import ConfigWrapper
# 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()
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.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).
- 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
- GitHub issue: #11689
- Fix PR: https://github.com/pydantic/pydantic/pull/11388
- First fixed release: 2.11.0
- 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.52
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 -…”
“This is due to a change in https://github.com/pydantic/pydantic/pull/11388 which cleaned up parts of the annotations evaluation”
Failure Signature (Search String)
- ImportError: cannot import name 'Company' from partially initialized module 'testm.company'
Error Message
Stack trace
Error Message
-------------
ImportError: cannot import name 'Company' from partially initialized module 'testm.company'
Minimal Reproduction
# 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
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.
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
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.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.