FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ by perrinjerome · Pull Request #113359 · python/cpython · GitHub

/ cpython Public

gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ - #113359

Merged
vsajip merged 5 commits into
python:mainfrom
perrinjerome:fix/exception_broken_getattr
Jan 16, 2024
Merged

gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__#113359
vsajip merged 5 commits into
python:mainfrom
perrinjerome:fix/exception_broken_getattr

Conversation

perrinjerome commented Dec 21, 2023
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

ghost commented Dec 21, 2023
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot commented Dec 21, 2023

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

perrinjerome marked this pull request as ready for review December 21, 2023 15:31
Comment thread Lib/traceback.py Outdated
try:
notes = getattr(exc_value, '__notes__', None)
except Exception:
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We don't swallow exceptions like this. What is your use case for defining an exception with a broken __getattr__?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I had much the same question on the issue. Python reporting bugs in user code does not seem like a python bug. OP needs to justify the python bug claim by quoting doc that says that user exceptions will by caught, or make this a feature request, with justification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for your feedback, I am sorry I did not explain enough. I have tried to add more context to the issue.

About not swallowing exceptions, I don't like it either (and I understand the negative feedback), maybe this patch should be adjusted to at least report that an exception occurred while getting the notes, by doing something like this instead ?

        try:
            self.__notes__ = getattr(exc_value, '__notes__', None)
        except Exception as e:
            self.__notes__ = [
                f'Ignored exception getting __notes__: {_safe_string(e, '__notes__', repr)}']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Unfortunately we do swallow exceptions like this. _safe_string() set a bad precedence since 2823f03.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I have updated the patch to include the "Ignored exception getting notes ..." in the notes as suggested above, from the discussion on the issue it seemed better to include information about the error in that case.

terryjreedy requested a review from vsajip December 22, 2023 14:28
Comment thread Lib/traceback.py Outdated
Comment thread Lib/test/test_traceback.py Outdated
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
vsajip merged commit 04fabe2 into python:main Jan 16, 2024
vsajip added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jan 16, 2024

Copy link
Copy Markdown

Thanks @perrinjerome for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @perrinjerome for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 16, 2024
…en __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>

Copy link
Copy Markdown

Sorry, @perrinjerome and @vsajip, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 04fabe22dd98b4d87f672254b743fbadd5206352 3.11

bedevere-app Bot commented Jan 16, 2024

Copy link
Copy Markdown

GH-114105 is a backport of this pull request to the 3.12 branch.

bedevere-app Bot removed the needs backport to 3.12 only security fixes label Jan 16, 2024
vsajip pushed a commit to vsajip/cpython that referenced this pull request Jan 16, 2024
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>

bedevere-app Bot commented Jan 16, 2024

Copy link
Copy Markdown

GH-114109 is a backport of this pull request to the 3.11 branch.

bedevere-app Bot removed the needs backport to 3.11 only security fixes label Jan 16, 2024
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>

bedevere-app Bot commented Jan 16, 2024

Copy link
Copy Markdown

GH-114118 is a backport of this pull request to the 3.11 branch.

2 similar comments

bedevere-app Bot commented Jan 16, 2024

Copy link
Copy Markdown

GH-114118 is a backport of this pull request to the 3.11 branch.

bedevere-app Bot commented Jan 16, 2024

Copy link
Copy Markdown

GH-114118 is a backport of this pull request to the 3.11 branch.

perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.11, because exception printing also happens in C
code. For simplicity, instead of including the repr of the exception
that happened during __getattr__, this just prints that an error
occured.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.11, because exception printing also happens in C
code. For simplicity, instead of including the repr of the exception
that happened during __getattr__, this just prints that an error
occured.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.11, because exception printing also happens in C
code.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.11, because exception printing also happens in C
code.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.11, because exception printing also happens in C
code.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>

bedevere-app Bot commented Jan 17, 2024

Copy link
Copy Markdown

GH-114173 is a backport of this pull request to the 3.12 branch.

perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
…en __getattr__ (pythonGH-113359)

cherry picked from commit 04fabe2

Adjusted for 3.12, because exception printing also happens in C
code.

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 20, 2024
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 20, 2024
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <perrinjerome@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL