Skip to content

Commit d0d0288

Browse files
author
John Lyu
committed
skip polymorphic in pydantic v1
1 parent 5d1bf5c commit d0d0288

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

sqlmodel/main.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,21 @@ def __new__(
539539
config_kwargs = {
540540
key: kwargs[key] for key in kwargs.keys() & allowed_config_kwargs
541541
}
542-
base_fields = {}
543-
base_annotations = {}
544-
for base in bases[::-1]:
545-
if issubclass(base, BaseModel):
546-
base_fields.update(get_model_fields(base))
547-
base_annotations.update(base.__annotations__)
548-
# use base_fields overwriting the ones from the class for inherit
549-
# if base is a sqlalchemy model, it's attributes will be an InstrumentedAttribute
550-
# thus pydantic will use the value of the attribute as the default value
551-
base_annotations.update(dict_used["__annotations__"])
552-
dict_used["__annotations__"] = base_annotations
553-
base_fields.update(dict_used)
554-
new_cls = super().__new__(
555-
cls, name, bases, base_fields, **config_kwargs
556-
)
542+
if IS_PYDANTIC_V2:
543+
base_fields = {}
544+
base_annotations = {}
545+
for base in bases[::-1]:
546+
if issubclass(base, BaseModel):
547+
base_fields.update(get_model_fields(base))
548+
base_annotations.update(base.__annotations__)
549+
# use base_fields overwriting the ones from the class for inherit
550+
# if base is a sqlalchemy model, it's attributes will be an InstrumentedAttribute
551+
# thus pydantic will use the value of the attribute as the default value
552+
base_annotations.update(dict_used["__annotations__"])
553+
dict_used["__annotations__"] = base_annotations
554+
base_fields.update(dict_used)
555+
dict_used = base_fields
556+
new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
557557
new_cls.__annotations__ = {
558558
**relationship_annotations,
559559
**pydantic_annotations,

0 commit comments

Comments
 (0)