pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

Fix MLFlowLogger.save_dir Windows file URI handling

Open littlebullGit opened this issue 5 months ago • 6 comments

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/

littlebullGit avatar Jul 19 '25 15:07 littlebullGit

@lantiga @williamFalcon , @Borda @ethanwharris @tchaton @justusschock Let me know your comments. Any changes I need to get this PR approved? It has been 2 weeks.

littlebullGit avatar Jul 31 '25 18:07 littlebullGit

@littlebullGit this requires @williamFalcon only as he is the single code-owner for loggers

Borda avatar Aug 13 '25 08:08 Borda

The failed check has nothing to do with the code fix. We can rerun the test once @williamFalcon reviewed the code.

littlebullGit avatar Aug 14 '25 13:08 littlebullGit

just rebased the PR

littlebullGit avatar Aug 30 '25 00:08 littlebullGit

build error did not seems related to my changes.

littlebullGit avatar Sep 02 '25 03:09 littlebullGit

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 79%. Comparing base (9ae18f7) to head (94db03c). :white_check_mark: All tests successful. No failed tests found.

:exclamation: There is a different number of reports uploaded between BASE (9ae18f7) and HEAD (94db03c). Click for more details.

HEAD has 1156 uploads less than BASE
Flag BASE (9ae18f7) HEAD (94db03c)
python3.12.7 80 7
lightning_fabric 74 0
pytest 149 0
cpu 289 28
python3.12 89 9
python3.10 30 3
lightning 140 13
python3.11 60 6
python 30 3
pytorch_lightning 75 15
pytorch2.7 15 3
pytest-full 140 28
pytorch2.1 30 6
pytorch2.2.2 15 3
pytorch2.6 15 3
pytorch2.3 15 3
pytorch2.8 15 3
pytorch2.4.1 10 2
pytorch2.9 15 3
pytorch2.5.1 10 2
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #20988     +/-   ##
=========================================
- Coverage      86%      79%     -8%     
=========================================
  Files         269      266      -3     
  Lines       23809    23760     -49     
=========================================
- Hits        20574    18661   -1913     
- Misses       3235     5099   +1864     

codecov[bot] avatar Dec 06 '25 01:12 codecov[bot]