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

exp: ignore workspace errors during push/pull #10128

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _onerror(entry, exc):
return _onerror


def _collect_indexes( # noqa: PLR0913
def _collect_indexes( # noqa: PLR0913,C901
repo,
targets=None,
remote=None,
Expand Down Expand Up @@ -80,6 +80,8 @@ def outs_filter(out: "Output") -> bool:

indexes[rev or "workspace"] = idx
except Exception as exc:
if rev == "workspace" and rev not in revs:
continue
if onerror:
onerror(rev, None, exc)
collection_exc = exc
Copy link
Member

@skshetry skshetry Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, it seems we never raise error, unless there are no indexes.
So, it seems dvc exp push will only fail if both of the workspace and experiment ref failed to get collected, or if we have no experiment to push, but only the workspace that has failed to get collected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an error only in the workspace, it will not fail, but it will loudly log an error message that looks like something went wrong. For example:

$ dvc exp push origin
ERROR: failed to collect 'workspace' - failed to parse 'stages.params_test.cmd' in 'dvc.yaml': Could not find 'params'
Pushed experiment rival-knap to Git remote 'origin'.
1 file uploaded

See also the test below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means we should not use logging.exception in this case (which should only be used before raising an exception), and the error message should just suggest that it was skipped due to the failure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means we should not use logging.exception in this case

Okay, I pushed another commit where I changed the logging to a warning. However, I am still skipping it for the workspace in the case where other revs were passed that don't include the workspace. It seems misleading to show warnings about the workspace rev in these cases since the workspace is irrelevant (for example, when pushing or pulling experiments).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I think the "right" solution here is not to fetch the workspace at all. It's wasteful in this case, but I was trying to limit the changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked where we are calling fetch, and I am fine with this PR, but I have to note we are changing behaviour here (i.e on --all-commits we are skipping workspace).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also uses this method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I see that's also documented in https://dvc.org/doc/command-reference/push#-A, so I'll limit to dvc exp push/pull for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also uses this method.

My apologies, _collect_indexes in fetch keeps on confusing me. Doesn't make any sense.
Especially with a small GitHhub diffview. 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, limited it to exp push/pull

Expand Down
15 changes: 15 additions & 0 deletions tests/func/experiments/test_remote.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pytest
from funcy import first

Expand Down Expand Up @@ -360,3 +362,16 @@ def test_get(tmp_dir, scm, dvc, exp_stage, erepo_dir, use_ref):
rev=exp_ref.name if use_ref else exp_rev,
)
assert (erepo_dir / "params.yaml").read_text().strip() == "foo: 2"


def test_push_invalid_workspace(
tmp_dir, scm, dvc, git_upstream, exp_stage, local_remote, caplog
):
dvc.experiments.run()

with open("dvc.yaml", mode="a") as f:
f.write("\ninvalid")

with caplog.at_level(logging.ERROR, logger="dvc"):
dvc.experiments.push(git_upstream.remote, push_cache=True)
assert "failed to collect" not in caplog.text