diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -708,18 +708,29 @@ def _string_setting(settings, name, defa def _substitute_values(mapping, substitutions): + result = {} try: - result = { + for key, value in mapping.items(): + # initialize without substitution first + result[key] = value + # Note: Cannot use regular replacements, since they would clash # with the implementation of ConfigParser. Using "format" instead. - key: value.format(**substitutions) - for key, value in mapping.items() - } - except KeyError as e: - raise ValueError( - 'Failed to substitute env variable: {}. ' - 'Make sure you have specified this env variable without ENV_ prefix'.format(e)) + try: + result[key] = value.format(**substitutions) + except KeyError as e: + env_var = '{}'.format(e.args[0]) + + msg = 'Failed to substitute: `{key}={{{var}}}` with environment entry. ' \ + 'Make sure your environment has {var} set, or remove this ' \ + 'variable from config file'.format(key=key, var=env_var) + + if env_var.startswith('ENV_'): + raise ValueError(msg) + else: + log.warning(msg) + except ValueError as e: log.warning('Failed to substitute ENV variable: %s', e) result = mapping