From 230e5c86d832cb75c40ca7c2e08e1af14a870847 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 27 Jan 2020 16:37:36 +0200 Subject: [PATCH] config: use validate() more explicitly --- dvc/config.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index cb0fd8e702..40f3052eb5 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -385,7 +385,7 @@ def load(self): if not self.should_validate: return - d = self.validate() + d = self.validate(self.config) self.config = configobj.ConfigObj(d, write_empty_values=True) def save(self, config=None): @@ -423,14 +423,9 @@ def _save(config): raise config.write() - def validate(self, config=None): - ret = copy.deepcopy(self.config) - - if config: - ret.merge(config) - + def validate(self, config): try: - return self.COMPILED_SCHEMA(ret.dict()) + return self.COMPILED_SCHEMA(config.dict()) except Invalid as exc: raise ConfigError(str(exc)) from exc @@ -499,7 +494,10 @@ def set(self, section, opt, value, level=None, force=True): config[section][opt] = value - self.validate(config) + result = copy.deepcopy(self.config) + result.merge(config) + self.validate(result) + self.save(config) def get(self, section, opt=None, level=None):