From ec3600eb8e7bdf0b484391b5413746d943b1f25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Tue, 4 Jan 2022 12:02:28 +0545 Subject: [PATCH] output: don't raise RemoteCacheRequiredError on instantiation, make it lazy --- dvc/output.py | 8 ++++---- tests/func/test_remote.py | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dvc/output.py b/dvc/output.py index a0c433cb2..f3d954448 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -326,9 +326,6 @@ class Output: self.desc = desc self.fs_path = self._parse_path(self.fs, fs_path) - if self.use_cache and self.odb is None: - raise RemoteCacheRequiredError(self.fs.scheme, self.fs_path) - self.obj = None self.isexec = False if self.IS_DEPENDENCY else isexec @@ -402,7 +399,10 @@ class Output: @property def odb(self): - return getattr(self.repo.odb, self.scheme) + odb = getattr(self.repo.odb, self.scheme) + if self.use_cache and odb is None: + raise RemoteCacheRequiredError(self.fs.scheme, self.fs_path) + return odb @property def cache_path(self): diff --git a/tests/func/test_remote.py b/tests/func/test_remote.py index ce09bfdb3..e764aef9f 100644 --- a/tests/func/test_remote.py +++ b/tests/func/test_remote.py @@ -247,14 +247,15 @@ def test_external_dir_resource_on_no_cache(tmp_dir, dvc, tmp_path_factory): # https://github.com/iterative/dvc/issues/2647, is some situations # (external dir dependency) cache is required to calculate dir md5 external_dir = tmp_path_factory.mktemp("external_dir") - (external_dir / "file").write_text("content") + file = external_dir / "file" dvc.odb.local = None with pytest.raises(RemoteCacheRequiredError): dvc.run( - cmd="echo hello world", - outs=[os.fspath(external_dir)], - single_stage=True, + cmd=f"echo content > {file}", + outs=[os.fspath(file)], + name="echo", + external=True, )