Skip to content

Commit 7c898cf

Browse files
authored
exp: ignore workspace errors during push/pull (#10128)
* exp: ignore workspace errors during push/pull * refactor fetch revs warning * mention failed revs are skipped * add workspace arg to brancher * pass workspace=False only for dvc exp push/pull
1 parent 1f07023 commit 7c898cf

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

dvc/repo/brancher.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def brancher(
2020
all_tags=False,
2121
all_commits=False,
2222
all_experiments=False,
23+
workspace=True,
2324
commit_date: Optional[str] = None,
2425
sha_only=False,
2526
num=1,
@@ -31,6 +32,7 @@ def brancher(
3132
all_branches (bool): iterate over all available branches.
3233
all_commits (bool): iterate over all commits.
3334
all_tags (bool): iterate over all available tags.
35+
workspace (bool): include workspace.
3436
commit_date (str): Keep experiments from the commits after(include)
3537
a certain date. Date must match the extended
3638
ISO 8601 format (YYYY-MM-DD).
@@ -73,7 +75,8 @@ def brancher(
7375

7476
logger.trace("switching fs to workspace")
7577
self.fs = LocalFileSystem(url=self.root_dir)
76-
yield "workspace"
78+
if workspace:
79+
yield "workspace"
7780

7881
revs = revs.copy() if revs else []
7982
if "workspace" in revs:

dvc/repo/experiments/pull.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,6 @@ def _pull_cache(
112112
refs = [refs]
113113
revs = list(exp_commits(repo.scm, refs))
114114
logger.debug("dvc fetch experiment '%s'", refs)
115-
repo.fetch(jobs=jobs, remote=dvc_remote, run_cache=run_cache, revs=revs)
115+
repo.fetch(
116+
jobs=jobs, remote=dvc_remote, run_cache=run_cache, revs=revs, workspace=False
117+
)

dvc/repo/experiments/push.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,6 @@ def _push_cache(
188188
assert isinstance(repo.scm, Git)
189189
revs = list(exp_commits(repo.scm, refs))
190190
logger.debug("dvc push experiment '%s'", refs)
191-
return repo.push(jobs=jobs, remote=dvc_remote, run_cache=run_cache, revs=revs)
191+
return repo.push(
192+
jobs=jobs, remote=dvc_remote, run_cache=run_cache, revs=revs, workspace=False
193+
)

dvc/repo/fetch.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _collect_indexes( # noqa: PLR0913
3232
recursive=False,
3333
all_commits=False,
3434
revs=None,
35+
workspace=True,
3536
max_size=None,
3637
types=None,
3738
config=None,
@@ -62,6 +63,7 @@ def outs_filter(out: "Output") -> bool:
6263
all_branches=all_branches,
6364
all_tags=all_tags,
6465
all_commits=all_commits,
66+
workspace=workspace,
6567
):
6668
try:
6769
repo.config.merge(config)
@@ -79,11 +81,11 @@ def outs_filter(out: "Output") -> bool:
7981
idx.data["repo"].onerror = _make_index_onerror(onerror, rev)
8082

8183
indexes[rev or "workspace"] = idx
82-
except Exception as exc:
84+
except Exception as exc: # noqa: BLE001
8385
if onerror:
8486
onerror(rev, None, exc)
8587
collection_exc = exc
86-
logger.exception("failed to collect '%s'", rev or "workspace")
88+
logger.warning("failed to collect '%s', skipping", rev or "workspace")
8789

8890
if not indexes and collection_exc:
8991
raise collection_exc
@@ -104,6 +106,7 @@ def fetch( # noqa: PLR0913
104106
all_commits=False,
105107
run_cache=False,
106108
revs=None,
109+
workspace=True,
107110
max_size=None,
108111
types=None,
109112
config=None,
@@ -148,6 +151,7 @@ def fetch( # noqa: PLR0913
148151
recursive=recursive,
149152
all_commits=all_commits,
150153
revs=revs,
154+
workspace=workspace,
151155
max_size=max_size,
152156
types=types,
153157
config=config,

dvc/repo/push.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def push( # noqa: PLR0913
4646
all_commits=False,
4747
run_cache=False,
4848
revs=None,
49+
workspace=True,
4950
glob=False,
5051
):
5152
from fsspec.utils import tokenize
@@ -87,6 +88,7 @@ def push( # noqa: PLR0913
8788
recursive=recursive,
8889
all_commits=all_commits,
8990
revs=revs,
91+
workspace=workspace,
9092
push=True,
9193
)
9294

tests/func/experiments/test_remote.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
import pytest
24
from funcy import first
35

@@ -360,3 +362,17 @@ def test_get(tmp_dir, scm, dvc, exp_stage, erepo_dir, use_ref):
360362
rev=exp_ref.name if use_ref else exp_rev,
361363
)
362364
assert (erepo_dir / "params.yaml").read_text().strip() == "foo: 2"
365+
366+
367+
def test_push_pull_invalid_workspace(
368+
tmp_dir, scm, dvc, git_upstream, exp_stage, local_remote, caplog
369+
):
370+
dvc.experiments.run()
371+
372+
with open("dvc.yaml", mode="a") as f:
373+
f.write("\ninvalid")
374+
375+
with caplog.at_level(logging.WARNING, logger="dvc"):
376+
dvc.experiments.push(git_upstream.remote, push_cache=True)
377+
dvc.experiments.pull(git_upstream.remote, pull_cache=True)
378+
assert "failed to collect" not in caplog.text

0 commit comments

Comments
 (0)