From 9716a849831c5c5c715648ca59141882cfab4795 Mon Sep 17 00:00:00 2001 From: BTatlock <105351010+BTatlock@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:06:44 +0000 Subject: [PATCH] Use PurePosixPath to fix imports on Windows No sources are added when importing zip files on Windows, as file paths are parsed using `pathlib.PureWindowsPath`. Schemas are defined using prefixes with trailing slashes, therefore file paths in zipfiles should instead be treated as `pathlib.PurePosixPath`s. Although Superset does not have official Windows support, this change fixes imports without changing the behaviour on Unix, since instantiating `pathlib.Path` creates a `pathlib.PurePosixPath`. --- superset/commands/importers/v1/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/commands/importers/v1/utils.py b/superset/commands/importers/v1/utils.py index 3999669356ae9..1e73886682ac0 100644 --- a/superset/commands/importers/v1/utils.py +++ b/superset/commands/importers/v1/utils.py @@ -14,7 +14,7 @@ # under the License. import logging -from pathlib import Path +from pathlib import Path, PurePosixPath from typing import Any, Dict, List, Optional from zipfile import ZipFile @@ -34,8 +34,8 @@ def remove_root(file_path: str) -> str: """Remove the first directory of a path""" - full_path = Path(file_path) - relative_path = Path(*full_path.parts[1:]) + full_path = PurePosixPath(file_path) + relative_path = PurePosixPath(*full_path.parts[1:]) return str(relative_path)