From c9d1aa9305e8383da5c33b917aafb3e0489e6638 Mon Sep 17 00:00:00 2001 From: Anis SMAIL Date: Fri, 7 Feb 2025 10:33:22 +0100 Subject: [PATCH] use workspace as key for sync in scan --- antarest/study/service.py | 18 ++++++++++-------- tests/storage/test_service.py | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/antarest/study/service.py b/antarest/study/service.py index 31bb80fa1f..9271e0dbdb 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -954,16 +954,17 @@ def sync_studies_on_disk( all_studies = [raw_study for raw_study in all_studies if directory in Path(raw_study.path).parents] else: all_studies = [raw_study for raw_study in all_studies if directory == Path(raw_study.path).parent] - studies_by_path = {study.path: study for study in all_studies} + studies_by_path_workspace = {(study.workspace, study.path): study for study in all_studies} # delete orphan studies on database - paths = [str(f.path) for f in folders] + # key should be workspace, path to sync correctly studies with same path in different workspace + workspace_paths = [(f.workspace, str(f.path)) for f in folders] for study in all_studies: if ( isinstance(study, RawStudy) and not study.archived - and (study.workspace != DEFAULT_WORKSPACE_NAME and study.path not in paths) + and (study.workspace != DEFAULT_WORKSPACE_NAME and (study.workspace, study.path) not in workspace_paths) ): if not study.missing: logger.info( @@ -990,11 +991,12 @@ def sync_studies_on_disk( self.repository.delete(study.id) # Add new studies - study_paths = [study.path for study in all_studies if study.missing is None] + study_paths = [(study.workspace, study.path) for study in all_studies if study.missing is None] missing_studies = {study.path: study for study in all_studies if study.missing is not None} for folder in folders: study_path = str(folder.path) - if study_path not in study_paths: + workspace = folder.workspace + if (workspace, study_path) not in study_paths: try: if study_path not in missing_studies.keys(): base_path = self.config.storage.workspaces[folder.workspace].path @@ -1004,7 +1006,7 @@ def sync_studies_on_disk( name=folder.path.name, path=study_path, folder=str(dir_name), - workspace=folder.workspace, + workspace=workspace, owner=None, groups=folder.groups, public_mode=PublicMode.FULL if len(folder.groups) == 0 else PublicMode.NONE, @@ -1039,8 +1041,8 @@ def sync_studies_on_disk( ) except Exception as e: logger.error(f"Failed to add study {folder.path}", exc_info=e) - elif directory and study_path in studies_by_path: - existing_study = studies_by_path[study_path] + elif directory and (workspace, study_path) in studies_by_path_workspace: + existing_study = studies_by_path_workspace[(workspace, study_path)] if self.storage_service.raw_study_service.update_name_and_version_from_raw_meta(existing_study): self.repository.save(existing_study) diff --git a/tests/storage/test_service.py b/tests/storage/test_service.py index 06a7d45b0f..bd860d1ba9 100644 --- a/tests/storage/test_service.py +++ b/tests/storage/test_service.py @@ -259,8 +259,8 @@ def test_study_listing(db_session: Session) -> None: @pytest.mark.unit_test def test_sync_studies_from_disk() -> None: now = datetime.utcnow() - ma = RawStudy(id="a", path="a") - fa = StudyFolder(path=Path("a"), workspace="", groups=[]) + ma = RawStudy(id="a", path="a", workspace="workspace1") + fa = StudyFolder(path=Path("a"), workspace="workspace1", groups=[]) mb = RawStudy(id="b", path="b") mc = RawStudy( id="c",