Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle auto push errors #10340

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions dvc/repo/experiments/executor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,13 @@ def auto_push(cls, dvc: "Repo") -> Iterator[None]:
git_remote = os.getenv(
DVC_EXP_GIT_REMOTE, exp_config.get("git_remote", "origin")
)
cls._validate_remotes(dvc, git_remote)
try:
cls._validate_remotes(dvc, git_remote)
except DvcException as exc:
logger.warning("Failed to validate remotes. Disabling auto push: %s", exc)

yield
return
yield
cls._auto_push(dvc, git_remote)

Expand All @@ -689,21 +695,24 @@ def _auto_push(
run_cache=True,
):
from dvc.ui import ui
from dvc.utils import format_link

branch = dvc.scm.get_ref(EXEC_BRANCH, follow=False)
link = format_link(
"https://dvc.org/doc/user-guide/experiment-management/sharing-experiments"
)
ui.write(
f"Pushing experiment to '{git_remote}'. Cancel with CTRL+C. "
f"See {link} for more info."
)
try:
ui.write(
f"Auto pushing experiment to '{git_remote}'. You can cancel the push "
"with CTRL+C. If you need to push your experiment again, you can "
f"retry later using `dvc exp push`",
)
dvc.experiments.push(
git_remote,
branch,
push_cache=push_cache,
run_cache=run_cache,
)
except BaseException as exc: # noqa: BLE001
except DvcException as exc:
logger.warning(
(
"Something went wrong while auto pushing experiment "
Expand Down
13 changes: 13 additions & 0 deletions tests/func/experiments/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,16 @@ def test_auto_push_on_save(
dvc.experiments.save(name=exp_name, force=True)

assert first(dvc.experiments.push(name=exp_name, git_remote=remote)) == expected_key


def test_auto_push_misconfigured(
tmp_dir, scm, dvc, git_upstream, local_remote, exp_stage, caplog
):
with dvc.config.edit() as conf:
conf["exp"]["auto_push"] = True
conf["exp"]["git_remote"] = "notfound"

exp_name = "foo"
with caplog.at_level(logging.WARNING, logger="dvc"):
dvc.experiments.run(exp_stage.addressing, params=["foo=2"], name=exp_name)
assert "Failed to validate remotes" in caplog.text
Loading