classification
Title: Regression in logging configuration
Type: behavior Stage: resolved
Components: Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: barry Nosy List: Steap, barry, lukasz.langa, miss-islington, ned.deily, vinay.sajip
Priority: release blocker Keywords: 3.7regression, patch

Created on 2018-06-07 23:00 by barry, last changed 2018-08-08 15:14 by lukasz.langa. This issue is now closed.

Files
File name Uploaded Description Edit
badconfig.py barry, 2018-06-07 23:00
Pull Requests
URL Status Linked Edit
PR 7509 closed barry, 2018-06-08 00:45
PR 7524 merged lukasz.langa, 2018-06-08 09:19
PR 7529 merged miss-islington, 2018-06-08 11:04
Messages (7)
msg318980 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2018-06-07 23:00
This looks like a serious regression in 3.7.  @ned.deily - I'm marking this as a release blocker, but feel free of course to downgrade it.

Run the following as

$ python3.6 badconfig.py
Hey, it works!

$ python3.7 badconfig.py
Traceback (most recent call last):
  File "../badconfig.py", line 77, in <module>
    fileConfig(inifile.name, defaults=GUNICORN_DEFAULTS)
  File "/Users/barry/projects/python/cpython/Lib/logging/config.py", line 65, in fileConfig
    cp = configparser.ConfigParser(defaults)
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 639, in __init__
    self._read_defaults(defaults)
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 1212, in _read_defaults
    self.read_dict({self.default_section: defaults})
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 754, in read_dict
    self.set(section, key, value)
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 1200, in set
    super().set(section, option, value)
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 895, in set
    value)
  File "/Users/barry/projects/python/cpython/Lib/configparser.py", line 403, in before_set
    "position %d" % (value, tmp_value.find('%')))
ValueError: invalid interpolation syntax in "{'generic': {'format': '%(asctime)s [%(process)d] [%(levelname)s] %(message)s', 'datefmt': '[%Y-%m-%d %H:%M:%S %z]', 'class': 'logging.Formatter'}}" at position 26

I'm still investigating, but wanted to get the bug filed asap.
msg318984 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2018-06-07 23:22
I think the regression is caused by the fix for bpo-23835

https://bugs.python.org/issue23835
msg319037 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-06-08 09:22
I'm very sorry for the trouble! And impressed at Barry's quick diagnosis.
msg319046 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-06-08 11:02
New changeset 214f18e49feb6a9d6c05aa09a4bb304905e81334 by Łukasz Langa in branch 'master':
bpo-33802: Do not interpolate in ConfigParser while reading defaults (GH-7524)
https://github.com/python/cpython/commit/214f18e49feb6a9d6c05aa09a4bb304905e81334
msg319065 - (view) Author: miss-islington (miss-islington) Date: 2018-06-08 14:01
New changeset f44203d782e397941c17d96e6a1f9dc1df08b3e6 by Miss Islington (bot) in branch '3.7':
bpo-33802: Do not interpolate in ConfigParser while reading defaults (GH-7524)
https://github.com/python/cpython/commit/f44203d782e397941c17d96e6a1f9dc1df08b3e6
msg323213 - (view) Author: Steap (Steap) Date: 2018-08-06 15:39
It seems like this regression has not completely been fixed: there are still issues with "None":

$ python3.6 -c 'import configparser; configparser.ConfigParser(defaults={"a": None})'

$ python3.7 -c 'import configparser; configparser.ConfigParser(defaults={"a": 1})'

$ python3.7 -c 'import configparser; configparser.ConfigParser(defaults={"a": None})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/configparser.py", line 638, in __init__
    self._read_defaults(defaults)
  File "/usr/lib/python3.7/configparser.py", line 1216, in _read_defaults
    self.read_dict({self.default_section: defaults})
  File "/usr/lib/python3.7/configparser.py", line 753, in read_dict
    self.set(section, key, value)
  File "/usr/lib/python3.7/configparser.py", line 1197, in set
    self._validate_value_types(option=option, value=value)
  File "/usr/lib/python3.7/configparser.py", line 1182, in _validate_value_types
    raise TypeError("option values must be strings")
TypeError: option values must be strings

Should "None" not be used, or should this bug be reopened?
msg323291 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-08-08 15:14
None is an invalid value in the configparser. It only accepts strings. See:

>>> cp = ConfigParser()
>>> cp['asd'] = {'a': None}
Traceback (most recent call last):
...
TypeError: option values must be strings



The DEFAULT section was an omission which is now fixed. You can use a RawConfigParser if you want to put invalid types as option values:

>>> rcp = RawConfigParser()
>>> rcp['asd'] = {'a': None}
>>>
History
Date User Action Args
2018-08-08 15:14:16lukasz.langasetmessages: + msg323291
2018-08-06 15:39:08Steapsetnosy: + Steap
messages: + msg323213
2018-06-08 16:55:14barrysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-08 14:01:58miss-islingtonsetnosy: + miss-islington
messages: + msg319065
2018-06-08 11:04:00miss-islingtonsetpull_requests: + pull_request7164
2018-06-08 11:02:52lukasz.langasetmessages: + msg319046
2018-06-08 10:04:35vinay.sajipsetnosy: + vinay.sajip
2018-06-08 09:22:13lukasz.langasetmessages: + msg319037
2018-06-08 09:19:48lukasz.langasetpull_requests: + pull_request7152
2018-06-08 03:39:17ned.deilysetnosy: + lukasz.langa
2018-06-08 00:45:25barrysetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request7137
2018-06-07 23:22:14barrysetmessages: + msg318984
2018-06-07 23:00:35barrycreate