Repository navigation
Conversation
…po root dvc.api.get_url()'s `path` argument is documented as relative to the root of `repo`, but Repo.get_data_index_entry() passed it through DVCFileSystem._get_key_from_relative(), which resolves plain relative paths against the filesystem's own getcwd() (itself derived from the real process cwd). When the caller's current directory was a subdirectory inside the repo, the path got resolved relative to that subdirectory instead of the repo root, so a valid output could no longer be found and get_url() raised OutputNotFoundError. Resolve the path against self.root_dir before computing the index key, using the existing cwd-independent DVCFileSystem._get_key(), so the lookup matches the documented repo-root-relative contract regardless of the caller's current directory. Fixes treeverse#11029.
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11126 +/- ##
==========================================
+ Coverage 90.68% 90.98% +0.29%
==========================================
Files 504 505 +1
Lines 39795 41145 +1350
Branches 3141 3263 +122
==========================================
+ Hits 36087 37434 +1347
- Misses 3042 3072 +30
+ Partials 666 639 -27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Akshaay1
marked this pull request as ready for review
October 31, 2026 09:37
This branch has not been deployed
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.
Problem
dvc.api.get_url()documents itspathargument as "relative to the root ofrepo", but it raisesOutputNotFoundErrorwhenever the caller's current working directory is a subdirectory inside the DVC repo, even though the exact same call succeeds from the repo root or from outside the repo entirely.Root Cause
Repo.get_data_index_entry()resolvespathby callingself.dvcfs.from_os_path(path)followed byDVCFileSystem._get_key_from_relative(). For a plain relative string,from_os_path()passes it through unchanged, and_get_key_from_relative()then resolves it viaself.abspath(path), which joins the path ontoself.getcwd()— the filesystem's notion of "current directory", itself derived from the real OS processcwdmapped into repo-relative terms.That's the right behavior for CLI commands like
dvc add(where a path really is relative to wherever the user is standing), butget_url()'s contract says the path is relative to the repo root, not the caller's cwd. So when cwd is<repo_root>/subdir, a path like"bar.txt"gets resolved to"subdir/bar.txt"instead of"bar.txt", and the lookup in the data index fails.Solution
In the
subreposbranch ofget_data_index_entry(), resolvepathagainstself.root_dirdirectly (joining only when it isn't already absolute) and look up the index key withDVCFileSystem._get_key(), which is the existing cwd-independent counterpart to_get_key_from_relative(). This mirrors theelsebranch just below it, which already resolves non-subrepo paths againstself.root_dirrather than cwd.Testing
test_get_url_from_subdirintests/func/api/test_data.py— creates a tracked file, chdirs into a subdirectory of the same repo, and assertsapi.get_url()still returns the correct remote URL.mainwithdvc.exceptions.OutputNotFoundError: Unable to find DVC file with output 'bar'(verified viagit stash), and passes with the fix.pytest tests/func/api/test_data.py -v: 35 passed.pytest tests/func/api/ tests/unit/fs/ tests/unit/repo/ tests/func/test_get_url.py -q(excluding one file that fails to collect due to an unrelated missing optionaldvc-s3dependency in this sandbox): 367 passed, 1 pre-existing unrelated failure (test_get_cloud_fs, same missingdvc-s3dependency, reproduces identically on unmodifiedmain).ruff check/ruff format --checkon the two changed files: clean (two pre-existingtoo-many-positional-argumentsfindings elsewhere indvc/repo/__init__.pyare unrelated to this change and present on unmodifiedmain).Related Issue
Closes #11029