diff --git a/antarest/study/model.py b/antarest/study/model.py index a9e0cea4e7..a07be97d1a 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -15,7 +15,7 @@ import secrets import uuid from datetime import datetime, timedelta -from pathlib import Path, PurePath +from pathlib import Path, PurePath, PurePosixPath from typing import TYPE_CHECKING, Annotated, Any, Dict, List, Mapping, Optional, Tuple, cast from antares.study.version import StudyVersion @@ -358,7 +358,7 @@ class NonStudyFolderDTO(AntaresBaseModel): so the user can navigate in the hierarchy """ - path: Path + path: PurePosixPath workspace: str name: str has_children: bool = Field( @@ -368,7 +368,7 @@ class NonStudyFolderDTO(AntaresBaseModel): model_config = ConfigDict(populate_by_name=True) @computed_field(alias="parentPath") - def parent_path(self) -> Path: + def parent_path(self) -> PurePosixPath: """ This computed field is convenient for the front. @@ -376,10 +376,17 @@ def parent_path(self) -> Path: Returns: the parent path of the current directory. Starting with the workspace as a root directory (we want /workspafe/folder1/sub... and not workspace/folder1/fsub... ). """ - workspace_path = Path(f"/{self.workspace}") + workspace_path = PurePosixPath(f"/{self.workspace}") full_path = workspace_path.joinpath(self.path) return full_path.parent + @field_validator("path", mode="before") + def to_posix(cls, path: Path) -> PurePosixPath: + """ + Always convert path to posix path. + """ + return PurePosixPath(path) + class WorkspaceMetadata(AntaresBaseModel): """ diff --git a/antarest/study/storage/explorer_service.py b/antarest/study/storage/explorer_service.py index d312f84552..b06534c008 100644 --- a/antarest/study/storage/explorer_service.py +++ b/antarest/study/storage/explorer_service.py @@ -11,6 +11,7 @@ # This file is part of the Antares project. import logging +from pathlib import PurePosixPath from typing import List from antarest.core.config import Config @@ -48,7 +49,7 @@ def list_dir( try: if is_non_study_folder(child, workspace.filter_in, workspace.filter_out): # we don't want to expose the full absolute path on the server - child_rel_path = child.relative_to(workspace.path) + child_rel_path = PurePosixPath(child.relative_to(workspace.path)) has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out) directories.append( NonStudyFolderDTO( diff --git a/tests/storage/business/test_explorer_service.py b/tests/storage/business/test_explorer_service.py index 60f5e20f1d..5e403cf39c 100644 --- a/tests/storage/business/test_explorer_service.py +++ b/tests/storage/business/test_explorer_service.py @@ -110,6 +110,9 @@ def test_list_dir_several_subfolders(config_scenario_a: Config): in result ) + assert str(result[0].path) == result[0].path.as_posix() + assert str(result[0].parent_path) == result[0].parent_path.as_posix() + @pytest.mark.unit_test def test_list_dir_in_empty_folder(config_scenario_a: Config):