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

RecursionError: maximum recursion depth exceeded while calling a Python object #251

Open
yourbuddyconner opened this issue Dec 12, 2023 · 6 comments

Comments

@yourbuddyconner
Copy link

yourbuddyconner commented Dec 12, 2023

Hey there!

I am testing out ariadne-codegen against a TypeGraphQL-generated API and am seeing issues at runtime that look pretty similar to #100.

Traceback (most recent call last):
  File "/Users/connerswann/code/protege-engine-sdk-python/protege_engine/cli.py", line 2, in <module>
    from protege import Protege
  File "/Users/connerswann/code/protege-engine-sdk-python/protege_engine/protege.py", line 1, in <module>
    from api.client import Client
  File "/Users/connerswann/code/protege-engine-sdk-python/protege_engine/api/__init__.py", line 5, in <module>
    from .client import Client
  File "/Users/connerswann/code/protege-engine-sdk-python/protege_engine/api/client.py", line 12, in <module>
    from .input_types import (
  File "/Users/connerswann/code/protege-engine-sdk-python/protege_engine/api/input_types.py", line 2846, in <module>
    class UserCreateWithoutFeedbackInput(BaseModel):
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 182, in __new__
    complete_model_class(
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 491, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/main.py", line 578, in __get_pydantic_core_schema__
    return __handler(__source)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema
    schema = self._generate_schema(obj)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _gene
...
    ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/typing.py", line 329, in <genexpr>
    ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/typing.py", line 327, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/typing.py", line 693, in _evaluate
    type_ = _type_check(
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/typing.py", line 164, in _type_check
    arg = _type_convert(arg, module=module, allow_special_forms=allow_special_forms)
  File "/usr/local/Caskroom/miniconda/base/envs/protege-engine-sdk-python/lib/python3.10/typing.py", line 141, in _type_convert
    if isinstance(arg, str):
RecursionError: maximum recursion depth exceeded while calling a Python object

I have a node SDK which uses GraphQL Codegen that handles this API just fine so thinking there's a bug in this library somewhere that is interacting weirdly with my schema.

@mat-sop
Copy link
Contributor

mat-sop commented Dec 12, 2023

Hey, which version of ariadne-codegen are you using? Could you also provide the schema used to generate your client, or another schema that reproduces the exception?

@yourbuddyconner
Copy link
Author

yourbuddyconner commented Dec 13, 2023

I updated the library I was using to 0.11 to be sure and it manifested the same behavior.

Unfortunately, this is an internal API I can't share details of publicly, but I am going to do some digging and review the schema and see what could be self-referential and revert back with thoughts.

@herman-mitish
Copy link

herman-mitish commented Jan 18, 2024

Hello! I am facing exactly the same issue with TypeGraphQL+Prisma generated API.
RecursionError: maximum recursion depth exceeded while calling a Python object
The only solution for me is to go back to 0.7.0, where it works ok, but every version above up until 0.11.0 would throw this error. I will try to provide simplified schema and example operation to reproduce

@herman-mitish
Copy link

I have made a small investigation, and it seems that starting from a certain level of complexity of the schema this error just happens. Though, this time I was able to get a little bit better error message:
RecursionError: maximum recursion depth exceeded in __instancecheck__

Most probably it could be resolved by setting higher recursion limit somewhere in the code, like:
import sys sys.setrecursionlimit(10000)

Here is a little reproduction I was able to make:
https://github.com/hermanmitish/ariadne-repro

@rafalp
Copy link
Contributor

rafalp commented Jan 18, 2024

Thank you for this reproduction. I'll give it a look but just the "too big schema causes problems" observation seems to point that we need to change recursive algorithm to linear one 🤔

@yourbuddyconner
Copy link
Author

Interesting... Poked this again today, and messed with the recursion limit setting -- still seeing a recursion error which indicates to me I might have a circular relationship in my DB schema, which theoretically should be fine because I set the field resolution depth to 3 on my backend, but I suspect it messes with the way you're rendering the pydantic types.

I suspect a switch to a linear algorithm might address both issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants