I'm working with an API where the schema for creating a group is effectively:
class Group(BaseModel):
identifier: str
I was hoping I could do this instead:
class Group(BaseModel):
groupname: str = Field(..., alias='identifier')
But with that configuration it's not possible to set the attribute value using the name groupname. That is, running this fails with a field required error:
>>> g = Group(groupname='foo')
pydantic.error_wrappers.ValidationError: 1 validation error for Group
identifier
field required (type=value_error.missing)
Is it is possible to use either the alias or the actual attribute name to set the attribute value? I was hoping that these two would be equivalent:
>>> Group(identifier='foo')
>>> Group(groupname='foo')