GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ by perrinjerome · Pull Request #113359 · python/cpython

Conversation

@perrinjerome

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: Exception with broken __getattr__ causes error rendering tracebacks #113358

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ticosax reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@perrinjerome
Fix rendering tracebacks with exceptions with a broken __getattr__
1f40d5f
@ghost

ghost commented Dec 21, 2023 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Dec 21, 2023
Exception with broken __getattr__ causes error rendering tracebacks #113358
Closed
@blurb-it
📜🤖 Added by blurb_it.
9eed42e
@perrinjerome
perrinjerome marked this pull request as ready for review December 21, 2023 15:31
@perrinjerome
perrinjerome requested a review from iritkatriel as a code owner December 21, 2023 15:31
@bedevere-app bedevere-app Bot added the awaiting review label Dec 21, 2023
iritkatriel
iritkatriel reviewed Dec 21, 2023
View reviewed changes
Comment thread Lib/traceback.py Outdated
try:
notes = getattr(exc_value, '__notes__', None)
except Exception:
pass

@iritkatriel iritkatriel Dec 21, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@terryjreedy terryjreedy Dec 21, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@perrinjerome perrinjerome Dec 22, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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)}']

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Dec 22, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@perrinjerome perrinjerome Jan 15, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@terryjreedy
terryjreedy requested a review from vsajip December 22, 2023 14:28
perrinjerome added 2 commits January 15, 2024 14:36
@perrinjerome
Display error accessing __notes__ along with the traceback
8651d3e
@perrinjerome
fixup! Display error accessing __notes__ along with the traceback
6ecf82d
vsajip
vsajip approved these changes Jan 15, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jan 15, 2024
iritkatriel
iritkatriel reviewed Jan 15, 2024
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

perrinjerome
perrinjerome commented Jan 15, 2024
View reviewed changes
Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@perrinjerome @iritkatriel
Apply suggestions from code review
6c6867a
Co-authored-by: Irit Katriel <[email protected]>
@vsajip
vsajip merged commit 04fabe2 into python:main Jan 16, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 16, 2024
@vsajip vsajip added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jan 16, 2024
@miss-islington-app

miss-islington-app Bot commented 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.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented 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.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 16, 2024
@perrinjerome @iritkatriel @miss-islington
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
d06a903
…en __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Jan 16, 2024

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned vsajip Jan 16, 2024
@bedevere-app 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
@perrinjerome @iritkatriel @vsajip
[3.11] pythongh-113358: Fix rendering tracebacks with exceptions with…
2157365
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app 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
@perrinjerome @iritkatriel
[3.11] pythongh-113358: Fix rendering tracebacks with exceptions with…
a839ff6
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
@perrinjerome @iritkatriel
[3.11] pythongh-113358: Fix rendering tracebacks with exceptions with…
616cd03
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
@perrinjerome perrinjerome mentioned this pull request Jan 16, 2024
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) #114118
Merged
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

2 similar comments
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
6114990
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 16, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
bc10ba2
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
acf3006
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
453b2e0
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
8c12e96
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 17, 2024
@perrinjerome @iritkatriel
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
ed7e67b
…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 <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
iritkatriel pushed a commit that referenced this pull request Jan 19, 2024
@perrinjerome
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a bro…
20f7cf2
…ken __getattr__ (GH-113359) (#114118)
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 20, 2024
@perrinjerome @iritkatriel
[3.12] pythongh-113358: Fix rendering tracebacks with exceptions with…
30964d1
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
perrinjerome added a commit to perrinjerome/cpython that referenced this pull request Jan 20, 2024
@perrinjerome @iritkatriel
[3.12] pythongh-113358: Fix rendering tracebacks with exceptions with…
3588252
… a broken __getattr__ (pythonGH-113359)

(cherry picked from commit 04fabe2)

Co-authored-by: Jérome Perrin <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
iritkatriel pushed a commit that referenced this pull request Jan 21, 2024
@perrinjerome
[3.12] gh-113358: Fix rendering tracebacks with exceptions with a bro…
00e8c9c
…ken __getattr__ (GH-113359) (#114173)
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
@perrinjerome @iritkatriel @kulikjak
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
d7e7d74
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@perrinjerome @iritkatriel @aisk
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
cb1bc3f
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@perrinjerome @iritkatriel @Glyphack
pythongh-113358: Fix rendering tracebacks with exceptions with a brok…
b4b5c9e
…en __getattr__ (pythonGH-113359)

Co-authored-by: Irit Katriel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@terryjreedy terryjreedy terryjreedy left review comments
@vsajip vsajip vsajip approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@vsajip vsajip

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@perrinjerome @vsajip @iritkatriel @serhiy-storchaka @terryjreedy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.