Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
echoyang7 committed Dec 5, 2023
1 parent 42ae2ba commit 3e7778c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lyrebird/mock/dm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,26 +960,31 @@ def update_group(self, _id, data, save=True, **kwargs):

message = self._adapter._update_group(data, **kwargs) if save else None

tree_target_node = self.get_target_node(self.tree, _id)
# Update node
# 1. Add new key into node
update_data = {k: data[k] for k in data if k not in self.update_group_ignore_keys}
node.update(update_data)
tree_target_node.update(update_data)

# 2. Remove deleted key in node
delete_keys = [k for k in node if k not in data and k not in self.update_group_ignore_keys and k not in self.unsave_keys]
for key in delete_keys:
node.pop(key)
tree_target_node.pop(key)

# 3. Update existed value
# 3. Modify abs_parent_path、parent、children
if old_name:
self.update_node_when_name_changed(node, _id, data['name'], old_name)
self.update_node_when_name_changed(tree_target_node, _id, data['name'], old_name)
if not message.get('message', None):
message['message'] = tree_target_node

# 4. Update tree
tree_target_node = self.get_target_node(self.tree, _id)
if tree_target_node:
tree_target_node.update(update_data)
for key in delete_keys:
tree_target_node.pop(key)
if old_name:
self.update_node_when_name_changed(tree_target_node, _id, data['name'], old_name)
if not message.get('message', None):
message['message'] = tree_target_node

return message

Expand Down Expand Up @@ -1023,9 +1028,10 @@ def update_data(self, _id, data):
if 'name' in data and node['name'] != data['name']:
self.update_node_when_name_changed(node, _id, data['name'], node['name'])
tree_target_node = self.get_target_node(self.tree, _id)
tree_target_node['name'] = data['name']
self.update_node_when_name_changed(tree_target_node, _id, data['name'], node['name'])
node['name'] = data['name']
if tree_target_node:
tree_target_node['name'] = data['name']
self.update_node_when_name_changed(tree_target_node, _id, data['name'], node['name'])
node['name'] = data['name']
self._adapter._update_data(data)
self._adapter._update_group(node)
return tree_target_node or node
Expand Down

0 comments on commit 3e7778c

Please sign in to comment.