Not A Pydantic Model Error
Description
This error is thrown when a strawberry.pydantic decorator is used on a class
that isnβt a Pydantic v2 model, for example the following code will throw this
error:
import strawberry
@strawberry.pydantic.typeclass User: name: str This happens because the strawberry.pydantic decorators read the fields from
the modelβs Pydantic definition. Pydantic dataclasses and Pydantic v1 models
(pydantic.v1.BaseModel ) arenβt supported either.
How to fix this error
You can fix this error by using strawberry.type (or strawberry.input and
strawberry.interface ) for classes that arenβt Pydantic models:
import strawberry
@strawberry.typeclass User: name: str Or by making the class a Pydantic v2 model:
import pydanticimport strawberry
@strawberry.pydantic.typeclass User(pydantic.BaseModel): name: str For Pydantic v1 models, use strawberry.experimental.pydantic .