From d42c8fbd14a544f1571b47354fde28264b53d890 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Wed, 24 Apr 2019 16:01:57 -0700 Subject: [PATCH] repro: persisting outputs invalidates build cache Fix #1852 --- dvc/stage.py | 4 ++++ tests/func/test_run.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/dvc/stage.py b/dvc/stage.py index 62ea6278f5..3e0e81e005 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -502,6 +502,10 @@ def create( else: stage.unprotect_outs() + if os.path.exists(path) and any(out.persist for out in stage.outs): + logger.warning("Build cache is ignored when persisting outputs.") + ignore_build_cache = True + if validate_state: if os.path.exists(path): if not ignore_build_cache and stage.is_cached: diff --git a/tests/func/test_run.py b/tests/func/test_run.py index 9015e4eab1..f789f1436d 100644 --- a/tests/func/test_run.py +++ b/tests/func/test_run.py @@ -1,6 +1,7 @@ import os import uuid +import logging import mock import shutil import filecmp @@ -948,3 +949,33 @@ def test(self): mock_run.assert_called_once() mock_checkout.assert_not_called() + + +class TestPersistentOutput(TestDvc): + def test_ignore_build_cache(self): + warning = "Build cache is ignored when persisting outputs." + + with open("immutable", "w") as fobj: + fobj.write("1") + + cmd = [ + "run", + "--overwrite-dvcfile", + "--deps", + "immutable", + "--outs-persist", + "greetings", + "echo hello>>greetings", + ] + + with self._caplog.at_level(logging.WARNING, logger="dvc"): + assert main(cmd) == 0 + assert warning not in self._caplog.text + + assert main(cmd) == 0 + assert warning in self._caplog.text + + # Even if the "immutable" dependency didn't change + # it should run the command again, as it is "ignoring build cache" + with open("greetings", "r") as fobj: + assert "hello\nhello\n" == fobj.read()