Skip to content

# Fix Remote URI Corruption and Leading Slash Truncation in storage.join() #7999

Description

@aayuxsh326

Fix Remote URI Corruption and Leading Slash Truncation in storage.join()

Background & Problem

In src/flyte/storage/_storage.py:

def join(*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.
    """
    return str(os.path.join(*paths))
  1. 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.
  2. 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".
  3. 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.
  • If local: use os.path.join(*paths).

Tests

[MODIFY] tests/internal/storage/test_storage.py

  • Add test_storage_join() test covering:
    • S3 / GCS / ABFS / Flyte remote URIs with multiple path components.
    • Remote URIs where subpaths contain leading slashes (/sub/file.txt).
    • Local relative and absolute paths.
    • Empty call storage.join().

Verification Plan

Automated Tests

  • Run Python verification tests exercising storage.join across remote URIs, Windows path styles, and leading-slash subpaths.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions