-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
Under certain conditions, Pydantic v2 will fail to resolve recursive type references and raise an error like this:
pydantic.errors.PydanticUndefinedAnnotation: name 'LegalEntity' is not defined
For further information visit https://errors.pydantic.dev/2.10/u/undefined-annotation
I've created a reproduction repo here.
Most relevant files are:
- https://github.com/RobertCraigie/pydantic-bug-repro/blob/926e1c6f5a751b41952121643b1077048d6b909b/src/pydantic_bug_repro/compensation.py
- https://github.com/RobertCraigie/pydantic-bug-repro/blob/926e1c6f5a751b41952121643b1077048d6b909b/src/pydantic_bug_repro/legal_entity.py
- https://github.com/RobertCraigie/pydantic-bug-repro/blob/926e1c6f5a751b41952121643b1077048d6b909b/src/pydantic_bug_repro/worker.py
Reproduction steps are in the readme.
It's worth noting that the same code works with Pydantic v1.
Python, Pydantic & OS Version
pydantic version: 2.10.5
pydantic-core version: 2.27.2
pydantic-core build: profile=release pgo=false
install path: .venv/lib/python3.9/site-packages/pydantic
python version: 3.9.18 (main, Feb 25 2024, 04:29:12) [Clang 17.0.6 ]
platform: macOS-15.1-arm64-arm-64bit
related packages: typing_extensions-4.12.2
commit: unknown