Hi,
when the strawberry.experimental.pydantic.type decorator tries to convert a Pydantic class to a strawberry type, an error occurs if one of the attributes of the Pydantic class is a nested subclass that has not yet been converted.
# pydantic.py
# my two pydantic classes
from pydantic import BaseModel, Field
class User(BaseModel):
id: int
username: str
name: Optional[str]
surname: Optional[str]
age: Optional[int]
sex: Optional[str]
posts: Optional[List["Post"]] = Field(default_factory=list)
class Post(BaseModel):
id: int
user: Optional["User"]
create_date: datetime = Field(default_factory=datetime.utcnow)
message: str
# graphql.py
# my two strawberry type classes
from .pydantic import Post, User
@strawberry.experimental.pydantic.type(model=Post, fields=[
'id',
'user',
'create_date',
'message',
])
class PostType:
...
@strawberry.experimental.pydantic.type(model=User, fields=[
"id",
"username",
"name",
"surname",
"age",
"sex",
"posts",
])
class UserType:
...
Error:
strawberry.experimental.pydantic.exceptions.UnregisteredTypeException: Cannot find a Strawberry Type for <class 'api_gateway.model.pydantic.User'> did you forget to register it?
Cause:
The problem is that the decorator doesn't wait until all the conversions are done and check again at the end.
It also doesn't matter in which order I write the statements, because each time the other class is not yet converted.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too