Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive model: maximum recursion depth exceeded #1370

Closed
iamstiil opened this issue Apr 6, 2020 · 1 comment · Fixed by #2338
Closed

Recursive model: maximum recursion depth exceeded #1370

iamstiil opened this issue Apr 6, 2020 · 1 comment · Fixed by #2338
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@iamstiil
Copy link

iamstiil commented Apr 6, 2020

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?

@iamstiil iamstiil added the bug V1 Bug related to Pydantic V1.X label Apr 6, 2020
@samuelcolvin
Copy link
Member

I don't think there's currently a solution for this. The most relevant discussion to this is #659, though I wouldn't all this a duplicate since that's specific to from_orm.

The short answer is that pydantic doesn't (yet) have any solution for detecting and coping with circular references.

If you have a suggestion of a solution, please comment on #659 or submit a demo PR. I have no idea off the top of my head, how hard it would be to use the same approach for from_orm, parse_obj and our case above - or if they're even particularly linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants