Model inheritance does not convert correctly
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the conversion using address_model.py and user_model.py, then inspect how PydanticObjectType handles the TUser.address field and the reported ConversionError. The change is done when models defined across modules and nested through TAddress convert successfully without this error.
Written by the indexing model from the issue text.
Description
Use Case Scenario
I've two pydantic models. Each in his own module (file). One Model, the TUser depends on the TAddress.
address_model.py
class TAddress(BaseModel):
id: Optional[int]
address: Optional[constr(max_length=100, strip_whitespace=True)]
city: Optional[constr(max_length=80, strip_whitespace=True)]
postal_code: Optional[constr(max_length=15, strip_whitespace=True)]
country: Optional[constr(max_length=3)]
user_model.py
class TUser(BaseModel):
id: UUID = None
email: Optional[EmailStr]
address: Optional[TAddress]
is_active: Optional[bool]
is_email_verified: Optional[bool]
created_at: Optional[datetime.datetime]
If I use the TUser model know for my PydanticObjectType
class UserType(PydanticObjectType):
class Meta:
model = TUser
I get the following error message:
graphene_pydantic.converters.ConversionError: Don't know how to convert the Pydantic field ModelField(name='address', type=Optional[TAddress], required=False, default=None) (<class 'app.address.serializers.TAddress'>)
It seems like that there is a problem when using pydantic models from different modules that depends on each other.
What is the solution for this use case?
Any idea?
- Dominant language
- Python
- Stars
- 249
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene-pydantic
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
graphql-python/graphene-pydantic#116 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
graphql-python/graphene-pydantic#111 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphene-pydantic#107 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
All issues in graphql-python/graphene-pydantic
Similar issues
-
python triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/semantic-kernel#14590 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
pinterest/pymemcache#662 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 62/100
gnocchixyz/gnocchi#1527 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
tenstorrent/tt-model-manager#181 ·
Maintainers usually reply within 1 day