Skip to content

Commit a2cfe62

Browse files
committed
Cleanup and fix getting diff from dictionary to be more safe
1 parent 88f00ea commit a2cfe62

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mergin/local_changes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BaseLocalChange:
1313
class LocalChange(BaseLocalChange):
1414
origin_checksum: Optional[str] = None
1515
chunks: List[str] = field(default_factory=list)
16-
diff: dict = field(default_factory=dict) # Assuming diff is a dict with relevant data
16+
diff: Optional[dict] = None
1717
upload_file: Optional[str] = None
1818

1919
def get_diff(self) -> Optional[BaseLocalChange]:

mergin/merginproject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ def get_push_changes(self):
439439
diff_id = str(uuid.uuid4())
440440
diff_name = path + "-diff-" + diff_id
441441
diff_file = self.fpath_meta(diff_name)
442-
print(f"Creating changeset for {path} - {diff_name}")
443442
try:
444443
self.geodiff.create_changeset(origin_file, current_file, diff_file)
445444
if self.geodiff.has_changes(diff_file):
@@ -704,13 +703,14 @@ def apply_push_changes(self, changes):
704703
self.geodiff.make_copy_sqlite(self.fpath(path), basefile)
705704
elif k == "updated":
706705
# in case for geopackage cannot be created diff (e.g. forced update with committed changes from wal file)
707-
if "diff" not in item:
706+
diff = item.get("diff")
707+
if not diff:
708708
self.log.info("updating basefile (copy) for: " + path)
709709
self.geodiff.make_copy_sqlite(self.fpath(path), basefile)
710710
else:
711711
self.log.info("updating basefile (diff) for: " + path)
712712
# better to apply diff to previous basefile to avoid issues with geodiff tmp files
713-
changeset = self.fpath_meta(item["diff"]["path"])
713+
changeset = self.fpath_meta(diff["path"])
714714
patch_error = self.apply_diffs(basefile, [changeset])
715715
if patch_error:
716716
# in case of local sync issues it is safier to remove basefile, next time it will be downloaded from server

0 commit comments

Comments
 (0)