KEMBAR78
Certain recursive type references are not resolved · Issue #11250 · pydantic/pydantic · GitHub
Skip to content

Certain recursive type references are not resolved #11250

@RobertCraigie

Description

@RobertCraigie

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:

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

Metadata

Metadata

Assignees

Labels

bug V2Bug related to Pydantic V2pendingIs unconfirmed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions