Strawberry Base Before Model Error
Description
This error is thrown when a strawberry.pydantic type, input or interface
extends a regular Strawberry type, input or interface before its Pydantic model,
for example the following code will throw this error:
import pydanticimport strawberry
@strawberry.interfaceclass Node: id: strawberry.ID
@strawberry.pydantic.typeclass Product(Node, pydantic.BaseModel): name: str Regular Strawberry types are dataclasses, so Node has its own __init__ . As
Node comes before pydantic.BaseModel in Product βs bases, its __init__
would replace Pydanticβs, and creating a Product would fail.
How to fix this error
You can fix this error by listing the Pydantic model first:
import pydanticimport strawberry
@strawberry.interfaceclass Node: id: strawberry.ID
@strawberry.pydantic.typeclass Product(pydantic.BaseModel, Node): name: str