Skip to content

Fix MLFlowLogger.save_dir Windows file URI handling (Fixes #20972) #20988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

littlebullGit
Copy link
Contributor

@littlebullGit littlebullGit commented Jul 19, 2025

Fix MLFlowLogger.save_dir Windows file URI handling

What does this PR do?

Fixes #20972

This PR fixes a bug in MLFlowLogger.save_dir where Windows absolute file URIs were being incorrectly parsed, resulting in malformed local paths that caused FileNotFoundError on Windows systems.

Problem:
When using [MLFlowLogger] with Windows absolute file URIs (e.g., file:///C:/Dev/example/mlruns), the [save_dir] property would return malformed paths like ///C:/Dev/example/mlruns instead of the expected C:/Dev/example/mlruns, causing file system operations to fail.

Solution:

  • Replace simple string slicing with proper URI parsing using urllib.parse.urlparse and urllib.request.url2pathname
  • Properly handle Windows absolute file URIs (e.g., file:///C:/path)
  • Add comprehensive tests for various file URI formats
  • Fix malformed paths like ///C:/path becoming C:/path on Windows

Changes:

  1. Core Fix: Updated MLFlowLogger.save_dir property to use standard library URI parsing methods
  2. Test Coverage: Added comprehensive test [test_mlflow_logger_save_dir_file_uri_handling] covering:
    • Unix-style absolute file URIs
    • Windows-style absolute file URIs
    • Relative file URIs
    • Non-file URIs (should return None)
    • URIs with URL-encoded special characters

📚 Documentation preview 📚: https://pytorch-lightning--20988.org.readthedocs.build/en/20988/

- Replace simple string slicing with urllib.parse.urlparse and url2pathname
- Properly handle Windows absolute file URIs (e.g., file:///C:/path)
- Add comprehensive tests for various file URI formats
- Fix malformed paths like ///C:/path becoming C:/path on Windows

Fixes Lightning-AI#20972
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jul 19, 2025
- Handle both proper file URIs (file:///path) and legacy format (file:/path)
- Proper URIs use urlparse/url2pathname for Windows compatibility
- Legacy format used by constructor returns path as-is
- Update tests to cover both formats and Windows behavior
@littlebullGit littlebullGit changed the title Fix MLFlowLogger.save_dir Windows file URI handling (#20972) Fix MLFlowLogger.save_dir Windows file URI handling (Fixes #20972) Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MLFlowLogger.save_dir mishandles absolute file: URIs on Windows
2 participants