Skip to content

Commit

Permalink
doesn't work because not every node can be UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
InnocentBug committed May 29, 2024
1 parent 3519925 commit 5d74d9a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/cript/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,29 +478,36 @@ def save(self, project: Project) -> None:
for node in project:
reverse_order_dict[node.uuid] = node

new_uuid_set = {}
new_uuid_set = set()
# Go through the nodes and save them one by one
for uuid in reverse_order_dict.keys_sorted_by_last_modified():
for uuid in reversed(reverse_order_dict.keys_sorted_by_last_modified()):
node = reverse_order_dict[uuid]

known_uuid_without_node = set(old_uuid_map.keys())
known_uuid_without_node = known_uuid_without_node.union(new_uuid_set)

# Remove current UUID, without raising error if it doesn't exist.
known_uuid_without_node.discard(node.uuid)

if uuid not in old_uuid_map:
# This is a POST
post_data = node.get_json(known_uuid=known_uuid_without_node, is_patch=False)
self._capsule_request(url_path=f"{node.node_type_snake_case}/{node.uuid}", method="POST", data=post_data.json)
new_uuid_set += post_data.handled_ids
response = self._capsule_request(url_path=f"/{node.node_type_snake_case}", method="POST", data=post_data.json)
response.raise_for_status()

for uid in post_data.handled_ids:
new_uuid_set = new_uuid_set.union(set((uid[2:],)))
else:
# This is a PATCH
patch_data = node.get_json(known_uuid=known_uuid_without_node, is_patch=True)
old_data = old_uuid_map[uuid].get_json(known_uuid=known_uuid_without_node, is_patch=True)
# Remove duplicates here.
diff_data = extract_differences(patch_data.json_dict, old_data.json_dict)
if len(diff_data) > 0:
self._capsule_request(url_path=f"{node.node_type_snake_case}/{node.uuid}", method="PATCH", data=json.dumps(diff_data))
new_uuid_set += post_data.handled_ids
response = self._capsule_request(url_path=f"/{node.node_type_snake_case}/{node.uuid}", method="PATCH", data=json.dumps(diff_data))
response.raise_for_status()
for uid in patch_data.handled_ids:
new_uuid_set = new_uuid_set.union(set((uid[2:],)))

def upload_file(self, file_path: Union[Path, str]) -> str:
# trunk-ignore-begin(cspell)
Expand Down

0 comments on commit 5d74d9a

Please sign in to comment.