Skip to content

Commit 99bd400

Browse files
committed
Make PartialModelMetaclass only modify BaseModel subclass
due to ModelMetaclass also being called in other situations where cls is not BaseModel. We don't want this to interfere in those situations. See https://github.com/pydantic/pydantic/blob/8128821b864db533b7c5c0c75589777c10d5cda7/pydantic/_internal/_model_construction.py#L85-L88
1 parent 866459e commit 99bd400

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

packages/syft/src/syft/types/syft_metaclass.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ def __new__(
3838
) -> type:
3939
cls = super().__new__(mcs, cls_name, bases, namespace, *args, **kwargs)
4040

41-
for field_info in cls.model_fields.values():
42-
if field_info.annotation is not None and field_info.is_required():
43-
field_info.annotation = field_info.annotation | EmptyType
44-
field_info.default = Empty
41+
if issubclass(cls, BaseModel):
42+
for field_info in cls.model_fields.values():
43+
if field_info.annotation is not None and field_info.is_required():
44+
field_info.annotation = field_info.annotation | EmptyType
45+
field_info.default = Empty
46+
47+
cls.model_rebuild(force=True)
4548

46-
cls.model_rebuild(force=True)
4749
return cls

0 commit comments

Comments
 (0)