2
0
Fork 0

Log warning if ambiguous config key detected

This commit is contained in:
Lance Edgar 2023-10-29 22:41:33 -05:00
parent 26b78adb56
commit cd2d16e6ac
2 changed files with 13 additions and 0 deletions

View file

@ -329,6 +329,8 @@ class WuttaConfig:
if not isinstance(value, configuration.Configuration): if not isinstance(value, configuration.Configuration):
return value return value
log.warning("ambiguous config key '%s' returns: %s", key, value)
# read from db last if so requested # read from db last if so requested
if usedb and not preferdb: if usedb and not preferdb:
value = self.get_from_db(key, session=session) value = self.get_from_db(key, session=session)

View file

@ -336,6 +336,17 @@ configure_logging = true
session.close() session.close()
def test_get_ambiguous(self):
config = conf.WuttaConfig()
# value is returned if key is not ambiguous
config.setdefault('foo', 'bar')
self.assertEqual(config.get('foo'), 'bar')
# but None is returned if key is ambiguous
config.setdefault('foo.bar', 'baz')
self.assertIsNone(config.get('foo'))
def test_require(self): def test_require(self):
config = conf.WuttaConfig() config = conf.WuttaConfig()
self.assertRaises(ConfigurationError, config.require, 'foo') self.assertRaises(ConfigurationError, config.require, 'foo')