Issue 31418: assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__
Created on 2017-09-11 12:49 by Oren Milman, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (7)
msg301872 - (view)
Author: Oren Milman (Oren Milman) *
Date: 2017-09-11 12:49
Date: 2017-09-11 13:25
Date: 2017-09-11 13:27
Date: 2017-09-13 10:02
Date: 2017-09-13 22:30
Date: 2017-09-14 06:41
The following code causes an assertion failure in PyErr_WriteUnraisable() (in Python/errors.c): class BadException(Exception): __module__ = None class BadClass: def __del__(self): raise BadException foo = BadClass() del foo this is because PyErr_WriteUnraisable() assumes that __module__ is a string, and passes it to _PyUnicode_EqualToASCIIId(), which asserts it received a string. what is the wanted behavior in such a case? should we ignore the bad __module__ and print '<unknown>' as the module name in the traceback?msg301873 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-09-11 13:25
Printing '<unknown>' LGTM. Implicit converting to str can raise a warning or exception if __module__ is a bytes object.msg301874 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-09-11 13:27
I think this patch doesn't need a test (which would require using a subprocess).msg302042 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-13 09:48
what do you mean by 'Implicit converting to str can raise a warning or exception if __module__ is a bytes object.'? should we treat __module__ differently in case it is a bytes object?msg302047 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-09-13 10:02
PyFile_WriteObject(moduleName, f, Py_PRINT_RAW) implicitly converts its argument to string. I mean that treating non-string moduleName the same way as string moduleName not equal to string "builtins" and calling PyFile_WriteObject() would cause other problem. Treating non-string moduleName the same way as moduleName==NULL LGTM.msg302126 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-09-13 22:30
New changeset f6e61df01536493f1280cd07639c7ff9bffb2cdc by Serhiy Storchaka (Oren Milman) in branch 'master': bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (#3539) https://github.com/python/cpython/commit/f6e61df01536493f1280cd07639c7ff9bffb2cdcmsg302145 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-09-14 06:41
New changeset 5dbb28ececdd0382d85b164aaf37bec1ae08036c by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6': [3.6] bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (GH-3539) (#3556) https://github.com/python/cpython/commit/5dbb28ececdd0382d85b164aaf37bec1ae08036c