I have a model which has a field called schema. In order to work around I have tried setting an alias. However, when using ORM mode... I get this error:
TypeError: 'dataset_schema' is an invalid keyword argument for Dataset
The sqlalchemy model field is called schema
Is there a way to work around this? Thanks!
python 3.7.5
pydantic 1.3
class SchemaSpecBase(BaseModel):
dataset_schema: Dict
class Config(BaseConfig):
allow_population_by_alias = True
fields = {'dataset_schema': {'alias': 'schema'}}
class SchemaSpecInDB(BaseMixinResource, SchemaSpecBase):
dataset: int
schema_version = int
schema_type = SchemaType
class Config:
orm_mode = True
allow_population_by_alias changed to allow_population_by_field_name in v1.
I suspect the problem is BaseMixinResource which is stopping inheritance of Config from SchemaSpecBase, but hard to know.
Does it work if you just use SchemaSpecBase with orm_mode = True added to it's config?
Updated allow_population_by_field_name.
Using SchemaSpecBase with orm_mode = True yields the same result.
Just using SchemaSpecBase directly... should using it this way produce an aliased field?
schemaspec = SchemaSpecBase.dict()
ah ha, needs to be schemaspec = SchemaSpecBase.dict(by_alias=True). Excellent. Thank you for the help!
Most helpful comment
ah ha, needs to be
schemaspec = SchemaSpecBase.dict(by_alias=True). Excellent. Thank you for the help!