diff --git a/server/common/app_config.py b/server/common/app_config.py index e0a49e46..3102bae0 100644 --- a/server/common/app_config.py +++ b/server/common/app_config.py @@ -95,8 +95,10 @@ class AppConfig(object): with open(config_file) as fyaml: config = yaml.load(fyaml, Loader=yaml.FullLoader) - self.server_config.update_from_config(config["server"], "server") - self.default_dataset_config.update_from_config(config["dataset"], "dataset") + if config.get("server"): + self.server_config.update_from_config(config["server"], "server") + if config.get("dataset"): + self.default_dataset_config.update_from_config(config["dataset"], "dataset") per_dataset_config = config.get("per_dataset_config", {}) for key, dataroot_config in per_dataset_config.items(): diff --git a/server/test/unit/common/test_app_config.py b/server/test/unit/common/test_app_config.py index 6b86d771..c3dd1436 100644 --- a/server/test/unit/common/test_app_config.py +++ b/server/test/unit/common/test_app_config.py @@ -206,3 +206,44 @@ class AppConfigTest(unittest.TestCase): # test config from specialization self.assertTrue(test_config.user_annotations__enable) + + def test_configfile_no_dataset_section(self): + # test a config file without a dataset section + + with tempfile.TemporaryDirectory() as tempdir: + configfile = os.path.join(tempdir, "config.yaml") + with open(configfile, "w") as fconfig: + config = """ + server: + multi_dataset: + dataroot: test_dataroot + + """ + fconfig.write(config) + + app_config = AppConfig() + app_config.update_from_config_file(configfile) + server_changes = app_config.server_config.changes_from_default() + dataset_changes = app_config.default_dataset_config.changes_from_default() + self.assertEqual(server_changes, [("multi_dataset__dataroot", "test_dataroot", None)]) + self.assertEqual(dataset_changes, []) + + def test_configfile_no_server_section(self): + # test a config file without a dataset section + + with tempfile.TemporaryDirectory() as tempdir: + configfile = os.path.join(tempdir, "config.yaml") + with open(configfile, "w") as fconfig: + config = """ + dataset: + user_annotations: + enable: false + """ + fconfig.write(config) + + app_config = AppConfig() + app_config.update_from_config_file(configfile) + server_changes = app_config.server_config.changes_from_default() + dataset_changes = app_config.default_dataset_config.changes_from_default() + self.assertEqual(server_changes, []) + self.assertEqual(dataset_changes, [("user_annotations__enable", False, True)])