FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: relax the schema check in update mixin by alaeddine-13 · Pull Request #1755 · docarray/docarray · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 7 additions & 2 deletions docarray/base_doc/mixins/update.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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__

Back | FazBrowse Home | New Git URL