Skip to content

Conversation

@dberenbaum
Copy link
Contributor

  • ❗ I have followed the Contributing to DVC checklist.

  • [N/A] πŸ“– If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.

dvc diff fails when there is no diff and hide_missing is true (hide_missing is implied when comparing two revisions) because CmdDiff.run tries to delete the not in cache info from an empty dict. It seemed easy enough to fix.

Not sure if we need a test for this. Couldn't find any relevant ones specific to the CmdDiff logic.

@dberenbaum dberenbaum requested a review from a team as a code owner February 18, 2022 15:53
@dberenbaum dberenbaum requested a review from efiop February 18, 2022 15:53
Copy link
Contributor

@daavoo daavoo left a comment

Choose a reason for hiding this comment

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

Not sure if we need a test for this. Couldn't find any relevant ones specific to the CmdDiff logic.

Could be something like:

https://github.com/iterative/dvc/blob/main/tests/unit/command/test_diff.py#L163

@dberenbaum
Copy link
Contributor Author

Thanks @daavoo! Added a test.

Comment on lines 223 to 227
def test_no_changes_hide_missing(mocker, capsys):
args = parse_args(["diff", "--json", "--hide-missing"])
cmd = args.func(args)
mocker.patch("dvc.repo.Repo.diff", return_value={})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use pytest.mark.parametrize in test_no_changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can change the above test test_no_changes to something like following:

@pytest.mark.parametrize("opts", ([], ["a_rev", "b_rev"], ["--hide-missing"]))
def test_no_changes(mocker, capsys, opts):
    args = parse_args(["diff", "--json", *opts])
    cmd = args.func(args)
    mocker.patch("dvc.repo.Repo.diff", return_value={})

    assert 0 == cmd.run()
    out, _ = capsys.readouterr()
    assert "{}" in out

    args = parse_args(["diff", *opts])
    cmd = args.func(args)
    assert 0 == cmd.run()
    out, _ = capsys.readouterr()
    assert not out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, just got a little lazy/sloppy here trying to fix this as quickly as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skshetry Updated the tests with parametrized options and output formats.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skshetry Pinging on this. Could you review the updated tests when you have a chance? πŸ™

@skshetry
Copy link
Collaborator

skshetry commented Feb 19, 2022

I'd prefer fixing this in repo.diff() to always return the same schema even if things didn't change.
So, instead of an empty dictionary, it should return this:

>>> repo.diff()
{
    'added': [],
    'deleted': [],
    'modified': [],
    'renamed': [],
    'not in cache': []
}

@dberenbaum
Copy link
Contributor Author

@skshetry Up to you. I went with the quickest fix since it seemed like a small enough issue to resolve quickly in CmdDiff without impacting repo.diff. Future changes to repo.diff could implement a consistent schema, but any reason not to handle this in CmdDiff also?

@daavoo daavoo linked an issue Feb 23, 2022 that may be closed by this pull request
@daavoo daavoo enabled auto-merge (rebase) March 2, 2022 17:45
@daavoo daavoo merged commit fc3f3ca into iterative:main Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diff: ERROR: unexpected error - 'not in cache'

3 participants