diff --git a/dvc/analytics.py b/dvc/analytics.py index 6e0e63694..d4914a33e 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -219,10 +219,10 @@ class Analytics(object): try: dvc_dir = Repo.find_dvc_dir() - config = Config(dvc_dir) except NotDvcRepoError: - config = Config(validate=False) - return config + dvc_dir = None + + return Config(dvc_dir, validate=False) @staticmethod def is_enabled(cmd=None): diff --git a/tests/unit/test_analytics.py b/tests/unit/test_analytics.py new file mode 100644 index 000000000..96209ce8f --- /dev/null +++ b/tests/unit/test_analytics.py @@ -0,0 +1,14 @@ +from dvc.analytics import Analytics +from dvc.config import Config +from dvc.repo import NotDvcRepoError + + +def test_broken_config(mocker, dvc_repo): + Config(dvc_repo.dvc_dir, validate=False).set("cache", "type", "unknown") + + assert Analytics._get_current_config() + + with mocker.patch( + "dvc.repo.Repo.find_dvc_dir", side_effect=NotDvcRepoError(".") + ): + assert Analytics._get_current_config()