Skip to content

api: resolve get_url path relative to repo root#11049

Open
miloudbelarebia wants to merge 1 commit into
treeverse:mainfrom
miloudbelarebia:apidata-get-url-subdir
Open

api: resolve get_url path relative to repo root#11049
miloudbelarebia wants to merge 1 commit into
treeverse:mainfrom
miloudbelarebia:apidata-get-url-subdir

Conversation

@miloudbelarebia

Copy link
Copy Markdown

Closes #11029

Bug

dvc.api.get_url() documents its path argument as relative to the root of
repo
, but it raised OutputNotFoundError whenever it was called from a
subdirectory of the repo:

os.chdir(repo_root / "subdir")
api.get_url("foo", repo=repo_root)   # OutputNotFoundError: Unable to find DVC file with output 'foo'

Cause

Repo.get_data_index_entry() (the only caller of get_url's lookup) builds
the data-index key via _DVCFileSystem._get_key_from_relative(), which resolves
a relative path against the filesystem's current working directory. From
subdir/, "foo" became the key ("subdir", "foo") instead of ("foo",), so
the 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_subdirget_url returns
    the 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) and tests/unit/fs/test_dvc.py (40)
pass locally; ruff check / ruff format --check are clean.

`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
@github-project-automation github-project-automation Bot moved this to Backlog in DVC Jun 2, 2026
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.98%. Comparing base (2431ec6) to head (95fbdac).
⚠️ Report is 205 commits behind head on main.

Files with missing lines Patch % Lines
dvc/repo/__init__.py 66.66% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dvc.api.get_url() throws error when working directory is a subdirectory of repo path

1 participant