From a04d183baa2680bdca0a80120ad43b06d16b44a4 Mon Sep 17 00:00:00 2001 From: Alaeddine Abdessalem Date: Tue, 22 Aug 2023 14:22:46 +0200 Subject: [PATCH] fix: relax the schema check in update mixin Signed-off-by: Alaeddine Abdessalem --- docarray/base_doc/mixins/update.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docarray/base_doc/mixins/update.py b/docarray/base_doc/mixins/update.py index c42900d3f97..c803e0a85cf 100644 --- a/docarray/base_doc/mixins/update.py +++ b/docarray/base_doc/mixins/update.py @@ -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') @@ -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)}' @@ -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__