Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.10a5 regression: AttributeError: 'NoneType' object has no attribute '__suppress_context__' in traceback.py #87312

Closed
The-Compiler mannequin opened this issue Feb 6, 2021 · 18 comments
Labels
3.10 only security fixes release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@The-Compiler
Copy link
Mannequin

The-Compiler mannequin commented Feb 6, 2021

BPO 43146
Nosy @gvanrossum, @terryjreedy, @vsajip, @The-Compiler, @hroncok, @ZackerySpytz, @pablogsal, @iritkatriel
PRs
  • bpo-43146: fix a recent (3.10) regression in handling None inputs to `tra… #24463
  • bpo-43146: fix None-handling in single-arg version of traceback.print… #24629
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-02-23.19:39:25.530>
    created_at = <Date 2021-02-06.15:54:16.813>
    labels = ['type-bug', 'library', '3.10', 'release-blocker']
    title = "3.10a5 regression: AttributeError: 'NoneType' object has no attribute '__suppress_context__' in traceback.py"
    updated_at = <Date 2021-02-23.19:39:25.530>
    user = 'https://github.com/The-Compiler'

    bugs.python.org fields:

    activity = <Date 2021-02-23.19:39:25.530>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-02-23.19:39:25.530>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2021-02-06.15:54:16.813>
    creator = 'The Compiler'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43146
    keywords = ['patch', '3.10regression']
    message_count = 18.0
    messages = ['386562', '386563', '386568', '386796', '386885', '386886', '386917', '386928', '387159', '387573', '387574', '387575', '387579', '387580', '387581', '387582', '387586', '387587']
    nosy_count = 8.0
    nosy_names = ['gvanrossum', 'terry.reedy', 'vinay.sajip', 'The Compiler', 'hroncok', 'ZackerySpytz', 'pablogsal', 'iritkatriel']
    pr_nums = ['24463', '24629']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43146'
    versions = ['Python 3.10']

    @The-Compiler
    Copy link
    Mannequin Author

    The-Compiler mannequin commented Feb 6, 2021

    After upgrading to 3.10a5, calling logging.exception("test") results in:

    --- Logging error \---
    
        Traceback (most recent call last):
          File "/usr/lib/python3.10/logging/__init__.py", line 1094, in emit
            msg = self.format(record)
          File "/usr/lib/python3.10/logging/__init__.py", line 938, in format
            return fmt.format(record)
          File "/usr/lib/python3.10/logging/__init__.py", line 682, in format
            record.exc_text = self.formatException(record.exc_info)
          File "/usr/lib/python3.10/logging/__init__.py", line 632, in formatException
            traceback.print_exception(ei[0], ei[1], tb, None, sio)
          File "/usr/lib/python3.10/traceback.py", line 113, in print_exception
            te = TracebackException(type(value), value, tb, limit=limit, compact=True)
          File "/usr/lib/python3.10/traceback.py", line 531, in __init__
            need_context = cause is None and not e.__suppress_context__
        AttributeError: 'NoneType' object has no attribute '__suppress_context__'

    That method is documented as "This function should only be called from an exception handler.", but the same also happens when e.g. calling traceback.print_exc() (without a current exception) or traceback.print_exception(None, None, None). Both worked fine before 3.10 Alpha 5, the code seems to do None-checks in other places, and typeshed also marks those arguments as Optional.

    This seems to have been introduced in #24179 for bpo-42877.

    @The-Compiler The-Compiler mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 6, 2021
    @iritkatriel
    Copy link
    Member

    Thanks, I’ll add the None check.

    @iritkatriel
    Copy link
    Member

    There's another such issue due to PR 22610 // bpo-26389:

    >>> traceback.format_exception(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 128, in format_exception
        value, tb = _parse_value_tb(exc, value, tb)
      File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 94, in _parse_value_tb
        return exc, exc.__traceback__
    AttributeError: 'NoneType' object has no attribute '__traceback__'

    @iritkatriel
    Copy link
    Member

    Marking as blocker because these are 3.10 regressions.

    @terryjreedy
    Copy link
    Member

    It seems to me that print_exception(None), etc, *should* raise something. Printing "NoneType: None\n" makes no sense to me since NoneType is not an exception. In 3.9, it raised TypeError for # of arguments.

    I do note that in 3.9
    >>> traceback.print_exception(None, None, None)
    NoneType: None

    I wonder what the rationale was. It isn't because these functions never raise.

    @iritkatriel
    Copy link
    Member

    In 3.9 you had to give exc,val,tb. In 3.10 the shortcut was added. bpo-26389.

    @hroncok
    Copy link
    Mannequin

    hroncok mannequin commented Feb 13, 2021

    JFYI, there are 2 affected Fedora packages (that we know of):

    visidata fails to build with Python 3.10: AttributeError: 'NoneType' object has no attribute '__suppress_context__'
    https://bugzilla.redhat.com/show_bug.cgi?id=1928145

    python-utils fails to build with Python 3.10: AttributeError: 'NoneType' object has no attribute '__suppress_context__'
    https://bugzilla.redhat.com/show_bug.cgi?id=1928081

    @iritkatriel
    Copy link
    Member

    I wonder what the rationale was. It isn't because these functions never raise.

    I think it's because sys.exc_info() can return None, None, None when there is no exceptions.

    @iritkatriel
    Copy link
    Member

    Let's split the print_exception(None) case (new issue) from the regression. I've updated the PR to fix only the latter, which is not controversial.

    I don't know what print_exception(None) should do.

    @gvanrossum
    Copy link
    Member

    New changeset 26f18b8 by Irit Katriel in branch 'master':
    bpo-43146: fix regression in traceback.print_exception(None) (GH-24463)
    26f18b8

    @gvanrossum
    Copy link
    Member

    Are you going to create a separate PR or a new issue for the other thing? (And what exactly *is* the other thing? Please summarize.)

    @iritkatriel
    Copy link
    Member

    The other thing is not related to the one reported here, but I found it while writing the test for this.

    We have a new API in 3.10, where you can do traceback.print_exception(ex) (so you don't need to give the whole type,val,tb triplet).

    But:

    >>> traceback.print_exception(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 110, in print_exception
        value, tb = _parse_value_tb(exc, value, tb)
      File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 94, in _parse_value_tb
        return exc, exc.__traceback__
    AttributeError: 'NoneType' object has no attribute '__traceback__'

    @gvanrossum
    Copy link
    Member

    So the PR just merged fixes that, right? Color me confused.

    @iritkatriel
    Copy link
    Member

    The PR just merged fixes the issue that was reported by Florian (what I broke). That impacted pre-3.10 APIs so was an actual regression.

    The issue with traceback.print_exception(None) is new to 3.10, and was introduced in bpo-26389.

    @gvanrossum
    Copy link
    Member

    So the remaining question is what to do for print_exception(None)? Honestly
    the current (new) behavior of printing NoneType: None seems fine.

    @iritkatriel
    Copy link
    Member

    So the remaining question is what to do for print_exception(None)?

    Yes.

    Honestly the current (new) behavior of printing NoneType: None seems fine.

    That's not the current behaviour - I removed that fix from the PR till we agree what to do. Currently we get the AttributeError.

    @iritkatriel
    Copy link
    Member

    The new PR makes it print NoneType: None, which is at least consistent with what the same functions do without the bpo-26389 shortcut.

    @gvanrossum
    Copy link
    Member

    New changeset b798ab0 by Irit Katriel in branch 'master':
    bpo-43146: fix None-handling in single-arg traceback.print_exception(None) (GH-24629)
    b798ab0

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants