skip polymorphic in pydantic v1
This commit is contained in:
parent
5d1bf5c2f3
commit
d0d0288797
@ -539,21 +539,21 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
|
|||||||
config_kwargs = {
|
config_kwargs = {
|
||||||
key: kwargs[key] for key in kwargs.keys() & allowed_config_kwargs
|
key: kwargs[key] for key in kwargs.keys() & allowed_config_kwargs
|
||||||
}
|
}
|
||||||
base_fields = {}
|
if IS_PYDANTIC_V2:
|
||||||
base_annotations = {}
|
base_fields = {}
|
||||||
for base in bases[::-1]:
|
base_annotations = {}
|
||||||
if issubclass(base, BaseModel):
|
for base in bases[::-1]:
|
||||||
base_fields.update(get_model_fields(base))
|
if issubclass(base, BaseModel):
|
||||||
base_annotations.update(base.__annotations__)
|
base_fields.update(get_model_fields(base))
|
||||||
# use base_fields overwriting the ones from the class for inherit
|
base_annotations.update(base.__annotations__)
|
||||||
# if base is a sqlalchemy model, it's attributes will be an InstrumentedAttribute
|
# use base_fields overwriting the ones from the class for inherit
|
||||||
# thus pydantic will use the value of the attribute as the default value
|
# if base is a sqlalchemy model, it's attributes will be an InstrumentedAttribute
|
||||||
base_annotations.update(dict_used["__annotations__"])
|
# thus pydantic will use the value of the attribute as the default value
|
||||||
dict_used["__annotations__"] = base_annotations
|
base_annotations.update(dict_used["__annotations__"])
|
||||||
base_fields.update(dict_used)
|
dict_used["__annotations__"] = base_annotations
|
||||||
new_cls = super().__new__(
|
base_fields.update(dict_used)
|
||||||
cls, name, bases, base_fields, **config_kwargs
|
dict_used = base_fields
|
||||||
)
|
new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
|
||||||
new_cls.__annotations__ = {
|
new_cls.__annotations__ = {
|
||||||
**relationship_annotations,
|
**relationship_annotations,
|
||||||
**pydantic_annotations,
|
**pydantic_annotations,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user