Skip to content

Commit

Permalink
fix(push/pull): don't fail on unsupported run cache (#10441)
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein authored May 27, 2024
1 parent 83ec952 commit 8f8d49d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from dvc.exceptions import DownloadError
from dvc.log import logger
from dvc.stage.cache import RunCacheNotSupported
from dvc.ui import ui
from dvc_data.index import DataIndex, FileStorage

Expand Down Expand Up @@ -136,6 +137,8 @@ def fetch( # noqa: PLR0913
try:
if run_cache:
self.stage_cache.pull(remote)
except RunCacheNotSupported as e:
logger.debug("failed to pull run cache: %s", e)
except DownloadError as exc:
failed_count += exc.amount

Expand Down
11 changes: 9 additions & 2 deletions dvc/repo/push.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from contextlib import suppress

from dvc.exceptions import InvalidArgumentError, UploadError
from dvc.log import logger
from dvc.stage.cache import RunCacheNotSupported
from dvc.ui import ui

from . import locked

logger = logger.getChild(__name__)


def _rebuild(idx, path, fs, cb):
from dvc_data.index import DataIndex, DataIndexEntry, Meta
Expand Down Expand Up @@ -95,8 +99,11 @@ def push( # noqa: PLR0913
"Multiple rev push is unsupported for cloud versioned remotes"
)

used_run_cache = self.stage_cache.push(remote) if run_cache else []
transferred_count += len(used_run_cache)
try:
used_run_cache = self.stage_cache.push(remote) if run_cache else []
transferred_count += len(used_run_cache)
except RunCacheNotSupported as e:
logger.debug("failed to push run cache: %s", e)

if isinstance(targets, str):
targets = [targets]
Expand Down
9 changes: 6 additions & 3 deletions tests/func/test_run_cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os

import pytest
Expand Down Expand Up @@ -231,13 +232,15 @@ def test_restore_pull(tmp_dir, dvc, run_copy, mocker, local_remote):
assert (tmp_dir / LOCK_FILE).exists()


def test_push_pull_unsupported(tmp_dir, dvc, mocker, run_copy):
def test_push_pull_unsupported(tmp_dir, dvc, mocker, run_copy, local_remote, caplog):
tmp_dir.gen("foo", "foo")
run_copy("foo", "bar", name="copy-foo-bar")
mocker.patch.object(
dvc.cloud, "get_remote_odb", side_effect=RunCacheNotSupported("foo")
)
with pytest.raises(RunCacheNotSupported):
with caplog.at_level(logging.DEBUG):
dvc.push(run_cache=True)
with pytest.raises(RunCacheNotSupported):
assert "failed to push run cache" in caplog.text
with caplog.at_level(logging.DEBUG):
dvc.pull(run_cache=True)
assert "failed to pull run cache" in caplog.text

0 comments on commit 8f8d49d

Please sign in to comment.