This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: logging.disable('WARN') breaks AsyncIO
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: OverLordGoldDragon, asvetlov, mbussonn, miss-islington, xmorel, yselivanov
Priority: normal Keywords: patch

Created on 2020-12-15 10:00 by OverLordGoldDragon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23786 merged mbussonn, 2020-12-15 18:08
PR 23796 merged miss-islington, 2020-12-16 09:43
PR 23797 merged miss-islington, 2020-12-16 09:44
Messages (10)
msg383040 - (view) Author: OverLordGoldDragon (OverLordGoldDragon) Date: 2020-12-15 10:00
import logging
with logging.disable('WARN'): pass

See: https://github.com/ipython/ipython/issues/12713
I'm not actually sure what's happening here, just reporting.
msg383053 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2020-12-15 13:19
Reporting what? Please elaborate.
msg383056 - (view) Author: OverLordGoldDragon (OverLordGoldDragon) Date: 2020-12-15 13:37
Everything's in the linked issue; in summary, the command kills IPython, and an IPython maintainer showed code suggesting the problem's rooted in CPython's improper handling of 'WARN' as alias for logging.WARN.
msg383061 - (view) Author: Xavier Morel (xmorel) * Date: 2020-12-15 14:24
The problem seems to be in the user code? As you were told by "Carreau", loggin.disable takes a logging level (an integer), since you're giving it a string which it dutifully stores, it blows up at the next logging call which happens to be in asyncio.

This is not an asyncio bug, nor is it a crash anymore than passing a broken key function to `sorted` is a *Python* crash.

At most it's an enancement request: `logging.disable` could raise a TypeError immediately or convert the value to a loglevel the way `setLevel` does instead of storing the broken value as-is (all it does currently is store the value it receives on the root logger without any check).
msg383083 - (view) Author: Matthias Bussonnier (mbussonn) * Date: 2020-12-15 17:36
I should have been more careful in my explanation in the upstream issue to have a complete report in here. 

I think that patching logging.disable to raise a type error immediately would be welcome; as the effect of storing a wrong type make any asyncio application fails in place that can be relatively remote from the location of the erroneous value, and could be quite hard to debug in other circumstances.
msg383085 - (view) Author: Xavier Morel (xmorel) * Date: 2020-12-15 18:19
> I think that patching logging.disable to raise a type error immediately would be welcome

FWIW `logging` has a built-in checker / converter[0] which is already used in a bunch of places (e.g. the aforementioned setLevel), it could just be added inside `disable` in the same way it's used in setLevel[1] and would uniformly convert "level names" to proper levels or raise an error. That seems like a really easy patch / contribution.

[0] https://github.com/python/cpython/blob/3.9/Lib/logging/__init__.py#L189

[1] https://github.com/python/cpython/blob/3.9/Lib/logging/__init__.py#L906
msg383086 - (view) Author: Xavier Morel (xmorel) * Date: 2020-12-15 18:21
Oh I now see you've created a PR to do essentially that, nm.
msg383130 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2020-12-16 09:43
New changeset b32d8b4f9bcd2e7d11240b6b9de0262cf8f5e09d by Matthias Bussonnier in branch 'master':
bpo-42644: Validate values in logging.disable() (#23786)
https://github.com/python/cpython/commit/b32d8b4f9bcd2e7d11240b6b9de0262cf8f5e09d
msg383133 - (view) Author: miss-islington (miss-islington) Date: 2020-12-16 10:10
New changeset 0a24a57888798905e3b8891c59e61ed4f1bfc5a8 by Miss Islington (bot) in branch '3.8':
bpo-42644: Validate values in logging.disable() (GH-23786)
https://github.com/python/cpython/commit/0a24a57888798905e3b8891c59e61ed4f1bfc5a8
msg383134 - (view) Author: miss-islington (miss-islington) Date: 2020-12-16 10:12
New changeset db63da7e5d4a98925a04f903a19bf3595b9c2c46 by Miss Islington (bot) in branch '3.9':
bpo-42644: Validate values in logging.disable() (GH-23786)
https://github.com/python/cpython/commit/db63da7e5d4a98925a04f903a19bf3595b9c2c46
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86810
2020-12-16 10:51:05asvetlovsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.7
2020-12-16 10:12:17miss-islingtonsetmessages: + msg383134
2020-12-16 10:10:54miss-islingtonsetmessages: + msg383133
2020-12-16 09:44:07miss-islingtonsetpull_requests: + pull_request22654
2020-12-16 09:43:57miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request22653
2020-12-16 09:43:47asvetlovsetmessages: + msg383130
2020-12-16 09:07:23asvetlovsettype: crash -> behavior
2020-12-16 09:07:06asvetlovsetcomponents: + Library (Lib), - asyncio
2020-12-15 18:21:14xmorelsetmessages: + msg383086
2020-12-15 18:19:47xmorelsetmessages: + msg383085
2020-12-15 18:08:46mbussonnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22643
2020-12-15 17:36:33mbussonnsetnosy: + mbussonn
messages: + msg383083
2020-12-15 14:24:28xmorelsetnosy: + xmorel
messages: + msg383061
2020-12-15 13:37:52OverLordGoldDragonsetmessages: + msg383056
2020-12-15 13:19:31asvetlovsetmessages: + msg383053
2020-12-15 10:00:46OverLordGoldDragoncreate