strawberry-graphql/strawberry

Mypy crashes if pydantic model and strawberry model has different fields

Closed this issue · 1 comments

Describe the Bug

running mypy with following models:

# models/user.py
import strawberry
from pydantic import BaseModel

class User(BaseModel):
    id: str
    account_id: str
    email: str
    name: str
    active: bool

@strawberry.experimental.pydantic.type(model=User)
class UserType:
    id: strawberry.auto
    email: strawberry.auto
    name: strawberry.auto

will crash with following stack traces:

Traceback (most recent call last):
  File "mypy/semanal.py", line 6714, in accept
  File "mypy/nodes.py", line 1142, in accept
  File "mypy/semanal.py", line 1621, in visit_class_def
  File "mypy/semanal.py", line 1706, in analyze_class
  File "mypy/semanal.py", line 1740, in analyze_class_body_common
  File "mypy/semanal.py", line 1811, in apply_class_plugin_hooks
  File "/var/app/server/functions/api/.venv/lib/python3.12/site-packages/strawberry/ext/mypy_plugin.py", line 471, in strawberry_pydantic_class_callback
    f.to_argument(
TypeError: PydanticModelField.to_argument() missing 1 required positional argument: 'api'

System Information

  • Strawberry version (if applicable): 0.224.1
  • pydantic version: 2.7.1

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Nevermind. Just saw that this has been fixed by #3462