strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.98k stars 531 forks source link

Maximum recursion depth exceeded when running codegen #3299

Open emosenkis opened 10 months ago

emosenkis commented 10 months ago

When trying to generate Python client code using strawberry codegen, I get RecursionError: maximum recursion depth exceeded:

│ .pyenv/versions/venv/lib/python3.10/site-packages/strawberry/codegen/query_codegen.py:657 in     │
│ <lambda>                                                                                         │
│                                                                                                  │
│   654 │   │   │   wrapper = (                                                                    │
│   655 │   │   │   │   GraphQLOptional                                                            │
│   656 │   │   │   │   if wrapper is None                                                         │
│ ❱ 657 │   │   │   │   else lambda t: GraphQLOptional(wrapper(t))  # type: ignore[misc]           │
│   658 │   │   │   )                                                                              │
│   659 │   │                                                                                      │
│   660 │   │   elif isinstance(type_, StrawberryList):                                            │
│                                                                                                  │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮           │
│ │       t = GraphQLObjectType(                                                       │           │
│ │           │   name='UpdateRecipientResultUpdateRecipientErrors',                   │           │
│ │           │   fields=[                                                             │           │
│ │           │   │   GraphQLField(                                                    │           │
│ │           │   │   │   name='message',                                              │           │
│ │           │   │   │   alias=None,                                                  │           │
│ │           │   │   │   type=GraphQLScalar(name='String', python_type=None),         │           │
│ │           │   │   │   default_value=None                                           │           │
│ │           │   │   )                                                                │           │
│ │           │   ],                                                                   │           │
│ │           │   graphql_typename=None                                                │           │
│ │           )                                                                        │           │
│ │ wrapper = <function QueryCodegen._unwrap_type.<locals>.<lambda> at 0x7fba74bfad40> │           │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯           │

Using Python 3.10 and strawberry 0.217.0

Upvote & Fund

Fund with Polar

jacobmoshipco commented 2 weeks ago

I am also having this issue on the same line. The wrapper function is getting rebound to call itself. I'm having the issue with a nullable list, but I'm unsure if that's the root cause, because there's already a test for it. I'm drafting a PR to fix this, but I can't figure out a test case that the current implementation is failing. Do you still have the code that was causing the issue?

jacobmoshipco commented 2 weeks ago

Found it! We have a test for Optional[List[int]], but the crash happens when there's an optional list of a non-scalar