diff --git a/dvc/api.py b/dvc/api.py index 5bf1517af..bf79b682e 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -34,7 +34,8 @@ def get_url(path, repo=None, rev=None, remote=None): raise OutputNotFoundError(path, repo) cloud = metadata.repo.cloud - hash_info = _repo.repo_tree.get_hash(path_info) + with _repo.state: + hash_info = _repo.repo_tree.get_hash(path_info) return cloud.get_url_for(remote, checksum=hash_info.value) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index a736103a1..acf8063ce 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -210,6 +210,9 @@ def test_get_url_granular(tmp_dir, dvc, s3): {"dir": {"foo": "foo", "bar": "bar", "nested": {"file": "file"}}} ) + expected_url = URLInfo(s3.url) / "5f/c28ea78987408341668eba6525ebd1.dir" + assert api.get_url("dir") == expected_url + expected_url = URLInfo(s3.url) / "ac/bd18db4cc2f85cedef654fccc4a4d8" assert api.get_url("dir/foo") == expected_url