fix inherited pk and add field accessor access to relations

This commit is contained in:
collerek
2021-06-25 13:32:31 +02:00
parent cc76e9b862
commit 107404c3e8
10 changed files with 516 additions and 61 deletions

View File

@ -584,7 +584,11 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
register_relation_in_alias_manager(field=field)
add_field_descriptor(name=name, field=field, new_model=new_model)
if new_model.Meta.pkname not in attrs["__annotations__"]:
if (
new_model.Meta.pkname
and new_model.Meta.pkname not in attrs["__annotations__"]
and new_model.Meta.pkname not in new_model.__fields__
):
field_name = new_model.Meta.pkname
attrs["__annotations__"][field_name] = Optional[int] # type: ignore
attrs[field_name] = None