Skip to content

Recursive model: maximum recursion depth exceeded #1370

@iamstiil

Description

@iamstiil

Bug

RecursionError: maximum recursion depth exceeded while calling a Python object

I get this error message, when using recursive models.

class A(BaseModel):
    ...

class B(A):
    key: List[B]
    ...

Using

from __future__ import annotations
from typings import ForwardRef

B = ForwardRef('B')
...
B.update_forward_refs()

does not make a difference aswell.

Issue #531 did not have any clue on how to solve this. The docs don't cover the usage with lists.

Hope you understand my issue here 😄

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.4
            pydantic compiled: True
                 install path: /usr/local/lib/python3.8/site-packages/pydantic
               python version: 3.8.2 (default, Feb 26 2020, 14:58:38)  [GCC 8.3.0]
                     platform: Linux-5.3.0-45-generic-x86_64-with-glibc2.2.5
     optional deps. installed: ['email-validator']

EDIT:
Just saw that the issue is pointed to in #524, but there is no response. Maybe there is a solution for it now?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions