graphql-python / graphql-python/graphene-pydantic

Model inheritance does not convert correctly

Open
#59 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
249
Forks
47
PR merge metrics
No merged PRs in 30d

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
```python
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
```python
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

```python
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) ()
```

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.