Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docarray/base_doc/mixins/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Dict, List, Type, TypeVar

from typing_inspect import get_origin

from docarray.utils._internal._typing import safe_issubclass

T = TypeVar('T', bound='UpdateMixin')
Expand Down Expand Up @@ -69,10 +70,10 @@ class MyDocument(BaseDoc):
---
:param other: The Document with which to update the contents of this
"""
if type(self) != type(other):
if not _similar_schemas(self, other):
raise Exception(
f'Update operation can only be applied to '
f'Documents of the same type. '
f'Documents of the same schema. '
f'Trying to update Document of type '
f'{type(self)} with Document of type '
f'{type(other)}'
Expand Down Expand Up @@ -188,3 +189,7 @@ def _group_fields(doc: 'UpdateMixin') -> _FieldGroups:
elif dict1 is not None and dict2 is not None:
dict1.update(dict2)
setattr(self, field, dict1)


def _similar_schemas(model1, model2):
return model1.__annotations__ == model2.__annotations__