Skip to content

Commit

Permalink
fix overwriting the whole object in mongo store instead overwrite onl…
Browse files Browse the repository at this point in the history
…y fields changed
  • Loading branch information
shubham3121 committed May 23, 2024
1 parent ce5db3a commit 3c54597
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions packages/syft/src/syft/service/network/node_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ...types.datetime import DateTime
from ...types.syft_migration import migrate
from ...types.syft_object import PartialSyftObject
from ...types.syft_object import SYFT_OBJECT_VERSION_1
from ...types.syft_object import SYFT_OBJECT_VERSION_2
from ...types.syft_object import SYFT_OBJECT_VERSION_3
from ...types.syft_object import SyftObject
Expand Down Expand Up @@ -321,11 +322,11 @@ def delete_route(


class NodePeerUpdate(PartialSyftObject):
id: UID
__canonical_name__ = "NodePeerUpdate"
__version__ = SYFT_OBJECT_VERSION_1

name: str
verify_key: SyftVerifyKey
node_routes: list[NodeRouteType]
node_type: NodeType
admin_email: str
ping_status: NodePeerConnectionStatus
ping_status_message: str
Expand Down
16 changes: 8 additions & 8 deletions packages/syft/src/syft/store/mongo_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,17 @@ def _update(
if has_permission or self.has_permission(
ActionObjectWRITE(uid=prev_obj.id, credentials=credentials)
):
# we don't want to overwrite Mongo's "id_" or Syft's "id" on update
obj_id = obj["id"]
for key, value in obj.to_dict(exclude_empty=True).items():
# we don't want to overwrite Mongo's "id_" or Syft's "id" on update
if key == "id":
# protected field
continue

# Set ID to the updated object value
obj.id = prev_obj["id"]
# Overwrite the value if the key is already present
setattr(prev_obj, key, value)

# Create the Mongo object
storage_obj = obj.to(self.storage_type)

# revert the ID
obj.id = obj_id
storage_obj = prev_obj.to(self.storage_type)

try:
collection.update_one(
Expand Down

0 comments on commit 3c54597

Please sign in to comment.