You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Remote URI Corruption and Leading Slash Truncation in storage.join()
Background & Problem
In src/flyte/storage/_storage.py:
defjoin(*paths: str) ->str:
""" Join multiple paths together. This is a wrapper around os.path.join. # TODO replace with proper join with fsspec root etc Args: paths: Paths to be joined. """returnstr(os.path.join(*paths))
Windows Path Corruption for Cloud URIs: On Windows, os.path.join("s3://bucket", "prefix", "file.txt") uses \ as separator, outputting "s3://bucket\\prefix\\file.txt". Cloud storage services and object stores reject backslashes in keys.
Subpaths with Leading Slash Wipe Out Prefix: In Python, os.path.join treats any argument beginning with / (e.g. storage.join("s3://bucket/dir", "/subfile.txt")) as an absolute root path and discards all preceding components, returning "/subfile.txt".
Empty arguments: Calling storage.join() with empty args should return "" cleanly.
User Review Required
Note
For remote paths (checked via is_remote(paths[0])), components will be joined using forward slashes (/), stripping redundant slashes from child components so prefixes are never dropped. For local paths, standard os.path.join behavior is preserved.
Proposed Changes
Core Library
[MODIFY] src/flyte/storage/_storage.py
Update join(*paths: str) -> str to check if paths[0] is a remote URI (using is_remote(paths[0])).
If remote: join using forward slashes /, stripping leading and trailing / from inner segments, preserving the protocol scheme.
Fix Remote URI Corruption and Leading Slash Truncation in
storage.join()Background & Problem
In
src/flyte/storage/_storage.py:os.path.join("s3://bucket", "prefix", "file.txt")uses\as separator, outputting"s3://bucket\\prefix\\file.txt". Cloud storage services and object stores reject backslashes in keys.os.path.jointreats any argument beginning with/(e.g.storage.join("s3://bucket/dir", "/subfile.txt")) as an absolute root path and discards all preceding components, returning"/subfile.txt".storage.join()with empty args should return""cleanly.User Review Required
Note
For remote paths (checked via
is_remote(paths[0])), components will be joined using forward slashes (/), stripping redundant slashes from child components so prefixes are never dropped. For local paths, standardos.path.joinbehavior is preserved.Proposed Changes
Core Library
[MODIFY] src/flyte/storage/_storage.py
join(*paths: str) -> strto check ifpaths[0]is a remote URI (usingis_remote(paths[0]))./, stripping leading and trailing/from inner segments, preserving the protocol scheme.os.path.join(*paths).Tests
[MODIFY] tests/internal/storage/test_storage.py
test_storage_join()test covering:/sub/file.txt).storage.join().Verification Plan
Automated Tests
storage.joinacross remote URIs, Windows path styles, and leading-slash subpaths.