From 2cdf27ce6c1f52390b84930b9aefddf6021b0041 Mon Sep 17 00:00:00 2001 From: Martin Varga Date: Fri, 21 Jul 2023 13:28:09 +0200 Subject: [PATCH] In file changesets details endpoint invoke full geopackage reconstruction if needed --- server/mergin/sync/public_api_controller.py | 2 ++ .../mergin/tests/test_project_controller.py | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/server/mergin/sync/public_api_controller.py b/server/mergin/sync/public_api_controller.py index 046ee0fc..521412bd 100644 --- a/server/mergin/sync/public_api_controller.py +++ b/server/mergin/sync/public_api_controller.py @@ -1250,6 +1250,8 @@ def get_resource_changeset(project_name, namespace, version_id, path): # noqa: project.storage.flush_geodiff_logger() # clean geodiff logger try: + if not os.path.exists(basefile): + version.project.storage.restore_versioned_file(path, version_id) if not os.path.exists(json_file): version.project.storage.geodiff.list_changes(changeset, json_file) if not os.path.exists(schema_file): diff --git a/server/mergin/tests/test_project_controller.py b/server/mergin/tests/test_project_controller.py index f2610084..87cb26c1 100644 --- a/server/mergin/tests/test_project_controller.py +++ b/server/mergin/tests/test_project_controller.py @@ -1848,24 +1848,32 @@ def test_file_diffs_chain(diff_project): @pytest.mark.parametrize("version, path, expected", changeset_data) def test_changeset_file(client, diff_project, version, path, expected): + pv = ProjectVersion.query.filter_by( + project_id=diff_project.id, name=version + ).first() + url = "/v1/resource/changesets/{}/{}/{}?path={}".format( test_workspace_name, test_project, version, path ) resp = client.get(url) assert resp.status_code == expected + if expected == 200 and is_versioned_file(path): + # remove gpkg file, so it is reconstructed on demand and request still works + f = pv.project.storage.file_path(os.path.join(version, path)) + if os.path.exists(f): + os.remove(f) + assert client.get(url).status_code == 200 + if resp.status_code == 200: - version = ProjectVersion.query.filter_by( - project_id=diff_project.id, name=version - ).first() - file = next((f for f in version.files if f["path"] == path), None) + file = next((f for f in pv.files if f["path"] == path), None) changeset = os.path.join( - version.project.storage.project_dir, file["diff"]["location"] + pv.project.storage.project_dir, file["diff"]["location"] ) json_file = "changeset" # create manually list changes - version.project.storage.geodiff.list_changes(changeset, json_file) + pv.project.storage.geodiff.list_changes(changeset, json_file) list_changes = json.loads(open(json_file, "r").read()) os.remove(json_file)