From ca3b8482eb5f6f4358c6ff5b5a702105f720eee7 Mon Sep 17 00:00:00 2001 From: Anis SMAIL Date: Thu, 6 Feb 2025 17:28:01 +0100 Subject: [PATCH] use workspace as a key for scan --- antarest/study/service.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/antarest/study/service.py b/antarest/study/service.py index 9c8667f09f..d2f71fcf74 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -883,16 +883,16 @@ 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] + 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( @@ -919,11 +919,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 @@ -933,7 +934,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, @@ -968,8 +969,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)