diff --git a/server/mergin/sync/models.py b/server/mergin/sync/models.py index 30c244a0..705a5e18 100644 --- a/server/mergin/sync/models.py +++ b/server/mergin/sync/models.py @@ -744,7 +744,7 @@ def __init__( fh.path: fh.id for fh in FileHistory.query.filter( FileHistory.id.in_( - self.project.latest_project_files.file_history_ids or {} + self.project.latest_project_files.file_history_ids ) ).all() } diff --git a/server/mergin/tests/test_project_controller.py b/server/mergin/tests/test_project_controller.py index 216f4b48..74421147 100644 --- a/server/mergin/tests/test_project_controller.py +++ b/server/mergin/tests/test_project_controller.py @@ -37,7 +37,7 @@ ProjectFilePath, ) from ..sync.files import ChangesSchema -from ..sync.schemas import ProjectListSchema, ProjectSchema +from ..sync.schemas import ProjectListSchema from ..sync.utils import generate_checksum, is_versioned_file from ..auth.models import User, UserProfile @@ -58,6 +58,7 @@ login, file_info, login_as_admin, + upload_file_to_project, ) from ..config import Configuration from ..sync.config import Configuration as SyncConfiguration @@ -2461,3 +2462,21 @@ def test_delete_diff_file(client): change=PushChangeType.DELETE.value, ).first() assert fh.path == "base.gpkg" and fh.diff is None + + +def test_cache_files_ids(client): + """Test caching latest project files when it is None""" + user = User.query.filter_by(username="mergin").first() + test_workspace = create_workspace() + project = create_project("no_file_history", test_workspace, user) + db.session.commit() + assert project.latest_project_files.file_history_ids is not None + project.latest_project_files.file_history_ids = None + db.session.commit() + assert project.latest_project_files.file_history_ids is None + # uploading to project caches + filename = "test.txt" + upload_file_to_project(project, filename, client) + fp = ProjectFilePath.query.filter_by(project_id=project.id, path=filename).first() + fh = FileHistory.query.filter_by(file_path_id=fp.id).first() + assert project.latest_project_files.file_history_ids == [fh.id]