From fdfdf41e1915f40c167f4632ddfdeeb1813f5c1b Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 7 Jun 2018 17:41:51 -0700 Subject: [PATCH] bpo-33802 - Fix regression in logging configuration In Python 3.6, defaults were not interpolated. --- Lib/configparser.py | 8 +++++++- Lib/test/test_logging.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Lib/configparser.py b/Lib/configparser.py index c88605feff7877d..16dacb72e332cfb 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -636,7 +636,13 @@ def __init__(self, defaults=None, dict_type=_default_dict, if converters is not _UNSET: self._converters.update(converters) if defaults: - self._read_defaults(defaults) + # For backward compatibility, defaults should do no interpolation. + try: + interpolation = self._interpolation + self._interpolation = Interpolation() + self._read_defaults(defaults) + finally: + self._interpolation = interpolation def defaults(self): return self._defaults diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 5098866237c8648..5efe219a50e0cf0 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1451,6 +1451,43 @@ def test_logger_disabling(self): self.apply_config(self.disable_test, disable_existing_loggers=False) self.assertFalse(logger.disabled) + def test_defaults_do_no_interpolation(self): + """bpo-33802 defaults should not get interpolated""" + ini = textwrap.dedent(""" + [formatters] + keys=default + + [formatter_default] + + [handlers] + keys=console + + [handler_console] + class=logging.StreamHandler + args=tuple() + + [loggers] + keys=root + + [logger_root] + formatter=default + handlers=console + """).strip() + with tempfile.NamedTemporaryFile(mode='w+t', encoding='utf-8') as fp: + fp.write(ini) + fp.flush() + logging.config.fileConfig(fp.name, defaults=dict( + version=1, + disable_existing_loggers=False, + formatters={ + "generic": { + "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", + "datefmt": "[%Y-%m-%d %H:%M:%S %z]", + "class": "logging.Formatter" + }, + }, + )) + class SocketHandlerTest(BaseTest):