Fix MLFlowLogger.save_dir Windows file URI handling
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.urlparseandurllib.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:/pathbecomingC:/pathon Windows
Changes:
-
Core Fix: Updated
MLFlowLogger.save_dirproperty to use standard library URI parsing methods -
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/
@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 this requires @williamFalcon only as he is the single code-owner for loggers
The failed check has nothing to do with the code fix. We can rerun the test once @williamFalcon reviewed the code.
just rebased the PR
build error did not seems related to my changes.
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