Skip to content

Commit 1b7eda2

Browse files
sharidasansharidas
authored andcommitted
Fix import issue without remote config in the target
Fix the import issue when target does not have remote config. Signed-off-by: Sujith H <sujith.h@gmail.com>
1 parent 7f5e4a9 commit 1b7eda2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

dvc/dependency/repo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from dvc.exceptions import OutputNotFoundError
1212
from dvc.exceptions import NoOutputInExternalRepoError
1313
from dvc.exceptions import PathMissingError
14+
from dvc.config import NoRemoteError
1415
from dvc.utils.fs import fs_copy
1516
from dvc.path_info import PathInfo
1617
from dvc.scm import SCM
@@ -91,7 +92,14 @@ def fetch(self):
9192

9293
out = repo.find_out_by_relpath(self.def_path)
9394
with repo.state:
94-
repo.cloud.pull(out.get_used_cache())
95+
try:
96+
repo.cloud.pull(out.get_used_cache())
97+
except NoRemoteError:
98+
# It would not be good idea to raise exception if the
99+
# file is already present in the cache
100+
if not self.repo.cache.local.changed_cache(out.checksum):
101+
return out
102+
raise
95103

96104
return out
97105

tests/func/test_import.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
from dvc.exceptions import DownloadError
1111
from dvc.exceptions import PathMissingError
1212
from dvc.exceptions import NoOutputInExternalRepoError
13+
from dvc.config import NoRemoteError
1314
from dvc.stage import Stage
1415
from dvc.system import System
1516
from dvc.utils.fs import makedirs
1617
from dvc.compat import fspath
18+
import dvc.data_cloud as cloud
1719
from tests.utils import trees_equal
1820

1921

@@ -56,6 +58,26 @@ def test_import_git_file(erepo_dir, tmp_dir, dvc, scm, src_is_dvc):
5658
}
5759

5860

61+
def test_import_cached_file(erepo_dir, tmp_dir, dvc, scm, monkeypatch):
62+
src = "some_file"
63+
dst = "some_file_imported"
64+
65+
with erepo_dir.chdir():
66+
erepo_dir.dvc_gen({src: "hello"}, commit="add a regular file")
67+
68+
tmp_dir.dvc_gen({dst: "hello"})
69+
(tmp_dir / dst).unlink()
70+
71+
remote_exception = NoRemoteError("dvc import")
72+
with patch.object(cloud.DataCloud, "pull", side_effect=remote_exception):
73+
tmp_dir.dvc.imp(fspath(erepo_dir), src, dst)
74+
75+
assert (tmp_dir / dst).is_file()
76+
assert filecmp.cmp(
77+
fspath(erepo_dir / src), fspath(tmp_dir / dst), shallow=False
78+
)
79+
80+
5981
@pytest.mark.parametrize("src_is_dvc", [True, False])
6082
def test_import_git_dir(erepo_dir, tmp_dir, dvc, scm, src_is_dvc):
6183
if not src_is_dvc:

0 commit comments

Comments
 (0)