First Check
Commit to Help
Example Code
from sqlmodel import Field, Relationship, SQLModel
class Address(SQLModel, table=True):
id: Optional[int] = Field(primary_key=True)
country: str
city: str
street: str
street_number: int
class Building(SQLModel, table=True):
id: int = Field(primary_key=True)
address_id: int = Field(foreign_key=f"{ADDRESSES}.id")
address: Address = Relationship()
age: int
class Config:
arbitrary_types_allowed = True
@validator('address', pre=True)
def validate_address(cls, v):
return Address.parse_obj(v)
# Importing Building produces the error "pydantic.errors.ConfigError: Validators defined with incorrect fields: validate_address (use check_fields=False if you're inheriting from the model and intended this)"
Description
I want to parse a Building instance from a nested dictionary d with the Building and Address class defined in the example code.
d = {
'address': {
'country': 'US',
'city': 'New York',
'street': 'Centre St',
'street_num': 1},
'age': 40
}
So far I have been unavailable to successfully execute Building.parse_obj(d). Commenting out the validator in Building solves the pydantic error bein raised but the address of the parsed building will be a dict instead of an Address instance
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.6.12
Additional Context
No response
First Check
Commit to Help
Example Code
Description
I want to parse a
Buildinginstance from a nested dictionarydwith theBuildingandAddressclass defined in the example code.So far I have been unavailable to successfully execute
Building.parse_obj(d). Commenting out the validator inBuildingsolves the pydantic error bein raised but the address of the parsed building will be a dict instead of anAddressinstanceOperating System
Windows
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.6.12
Additional Context
No response