Fix evaluation priority of the bootstrap settings

Closes GitLab issue #702. Thanks to Kevin Pawsey (@kevinpawsey) for
the report and the help debuging the issue.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-12-09 00:21:15 -04:00
parent d345f8e838
commit 4e65a436c7
5 changed files with 132 additions and 11 deletions

View File

@@ -141,12 +141,24 @@ class BaseSetting(object):
By default will try to get the value from the namespace symbol table,
then the configuration file, and finally from the environment.
"""
# Resolution order
# 1 - Environment
# 2 - Config
# 3 - Global
# 4 - Default
try:
return self.namespace.global_symbol_table.get(
self.name, self.namespace.get_config_file_setting(name=self.name)
)
except SettingNamespaceSingleton.SettingNotFound:
return self.load_environment_value()
except SettingNamespaceSingleton.SettingNotFound:
try:
return self.namespace.get_config_file_setting(name=self.name)
except SettingNamespaceSingleton.SettingNotFound:
try:
return self.namespace.global_symbol_table[self.name]
except KeyError:
if self.has_default:
return self.get_default_value()
else:
raise SettingNamespaceSingleton.SettingNotFound
def load_environment_value(self):
value = self._get_environment_value()
@@ -161,10 +173,7 @@ class BaseSetting(object):
)
)
else:
if self.has_default:
return self.get_default_value()
else:
raise SettingNamespaceSingleton.SettingNotFound
raise SettingNamespaceSingleton.SettingNotFound
class FilesystemBootstrapSetting(BaseSetting):
@@ -190,7 +199,13 @@ class FilesystemBootstrapSetting(BaseSetting):
because not even the config file setup has completed.
This setting only supports being set from the environment.
"""
return self.load_environment_value()
try:
return self.load_environment_value()
except SettingNamespaceSingleton.SettingNotFound:
if self.has_default:
return self.get_default_value()
else:
raise SettingNamespaceSingleton.SettingNotFound
class MediaBootstrapSetting(FilesystemBootstrapSetting):