gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__#113359
Conversation
|
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 |
| try: | ||
| notes = getattr(exc_value, '__notes__', None) | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
We don't swallow exceptions like this. What is your use case for defining an exception with a broken __getattr__?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)}']There was a problem hiding this comment.
Unfortunately we do swallow exceptions like this. _safe_string() set a bad precedence since 2823f03.
There was a problem hiding this comment.
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.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
|
Thanks @perrinjerome for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
|
Thanks @perrinjerome for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
…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>
|
Sorry, @perrinjerome and @vsajip, I could not cleanly backport this to |
|
GH-114105 is a backport of this pull request to the 3.12 branch. |
… 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>
|
GH-114109 is a backport of this pull request to the 3.11 branch. |
… 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>
… 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>
|
GH-114118 is a backport of this pull request to the 3.11 branch. |
2 similar comments
|
GH-114118 is a backport of this pull request to the 3.11 branch. |
|
GH-114118 is a backport of this pull request to the 3.11 branch. |
…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>
…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>
…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>
…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>
…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>
|
GH-114173 is a backport of this pull request to the 3.12 branch. |
…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>
… 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>
… 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>
…en __getattr__ (pythonGH-113359) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
…en __getattr__ (pythonGH-113359) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
…en __getattr__ (pythonGH-113359) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.