api: resolve get_url path relative to repo root#11049
Open
miloudbelarebia wants to merge 1 commit into
Open
Conversation
`dvc.api.get_url()` documents `path` as relative to the repo root, but `get_data_index_entry` resolved a relative path against the current working directory. From a subdirectory of the repo this produced a wrong index key and raised OutputNotFoundError. Anchor the path at the dvcfs root marker. Closes treeverse#11029
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11049 +/- ##
==========================================
+ Coverage 90.68% 90.98% +0.29%
==========================================
Files 504 505 +1
Lines 39795 41147 +1352
Branches 3141 3264 +123
==========================================
+ Hits 36087 37436 +1349
- Misses 3042 3071 +29
+ Partials 666 640 -26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11029
Bug
dvc.api.get_url()documents itspathargument as relative to the root ofrepo, but it raisedOutputNotFoundErrorwhenever it was called from asubdirectory of the repo:
Cause
Repo.get_data_index_entry()(the only caller ofget_url's lookup) buildsthe data-index key via
_DVCFileSystem._get_key_from_relative(), which resolvesa relative path against the filesystem's current working directory. From
subdir/,"foo"became the key("subdir", "foo")instead of("foo",), sothe entry was not found. From the repo root (or outside the repo) the cwd
happened to map to the root marker, which is why the bug only showed up in a
subdirectory.
Fix
Anchor the (root-relative) path at the dvcfs root marker before computing the
key, so the lookup no longer depends on the current working directory. This
matches the documented contract of
path.Tests
tests/func/api/test_data.py::test_get_url_from_subdir—get_urlreturnsthe same URL from the repo root and from a subdirectory. Fails before the fix
(
OutputNotFoundError), passes after.All
tests/func/api/test_data.py(35) andtests/unit/fs/test_dvc.py(40)pass locally;
ruff check/ruff format --checkare clean.