From 910a67b35f8180afacf41dd4e886938974af60aa Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 8 Nov 2019 02:26:12 +0200 Subject: [PATCH] analytics: don't verify config from repo Otherwise this will raise an exception from analytics worker: ``` dvc config cache.type sometypo ``` But running that same command with `--system` or `--global` flag outside of repo won't raise that. Also need to better handle ConfigObjError, but that is a separate issue. --- dvc/analytics.py | 6 +++--- tests/unit/test_analytics.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_analytics.py 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()