experiments: fix git stash mtime race condition (#4727)

This commit is contained in:
Peter Rowlands (변기호)
2020-10-15 13:26:17 +03:00
committed by GitHub
parent 8f8c561d1b
commit 9d7e483599
2 changed files with 11 additions and 6 deletions
+10 -3
View File
@@ -263,9 +263,6 @@ class Experiments:
if os.path.getsize(tmp):
logger.debug("Patching experiment workspace")
self.scm.repo.git.apply(tmp)
elif not params and not allow_unchanged:
# experiment matches original baseline
raise UnchangedExperimentError(rev)
finally:
remove(tmp)
@@ -273,6 +270,10 @@ class Experiments:
if params:
self._update_params(params)
if not self.scm.is_dirty(untracked_files=True) and not allow_unchanged:
# experiment matches original baseline
raise UnchangedExperimentError(rev)
# save additional repro command line arguments
self._pack_args(*args, **kwargs)
@@ -317,6 +318,12 @@ class Experiments:
with modify_data(path, tree=self.exp_dvc.tree) as data:
_update(data, params[params_fname])
# Force params file changes to be staged in git
# Otherwise in certain situations the changes to params file may be
# ignored when we `git stash` them since mtime is used to determine
# whether the file is dirty
self.scm.add(list(params.keys()))
def _commit(
self, exp_hash, check_exists=True, create_branch=True, checkpoint=False
):
+1 -3
View File
@@ -1,7 +1,6 @@
from textwrap import dedent
import pytest
from flaky.flaky_decorator import flaky
from funcy import first
from dvc.utils.serialize import PythonFileCorruptedError
@@ -206,8 +205,6 @@ def test_update_py_params(tmp_dir, scm, dvc):
dvc.experiments.run(stage.addressing, params=["params.py:INT=2a"])
# See: https://github.com/iterative/dvc/issues/4717
@flaky(max_runs=3, min_passes=1)
def test_extend_branch(tmp_dir, scm, dvc):
tmp_dir.gen("copy.py", COPY_SCRIPT)
tmp_dir.gen("params.yaml", "foo: 1")
@@ -232,6 +229,7 @@ def test_extend_branch(tmp_dir, scm, dvc):
)
exp_b = first(results)
assert exp_a != exp_b
assert dvc.experiments._get_branch_containing(exp_b) == exp_branch
dvc.experiments.checkout(exp_a)