Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-98458: unittest: bugfix for infinite loop while handling chained exceptions that contain cycles #98459

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

Merged
merged 8 commits into from
Dec 4, 2022

Conversation

AlexTate
Copy link
Contributor

@AlexTate AlexTate commented Oct 19, 2022

…ed exception in TestResult._clean_tracebacks()
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost
Copy link

ghost commented Oct 19, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

Can you add a test for this? It would be good to also test the more exotic case of a loop of mutually-chained exceptions, such as:

try:
    raise ValueError(1)
except ValueError as e:
    try:
        raise KeyError(2) from e
    except KeyError as e2:
        raise e from e2

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

Please add a test for this and address @iritkatriel's review.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

…cks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
@AlexTate
Copy link
Contributor Author

AlexTate commented Dec 1, 2022

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@kumaraditya303: please review the changes made to this pull request.

@AlexTate AlexTate changed the title gh-98458: unittest: bugfix for infinite loop while handling self-referencing explicit exception gh-98458: unittest: bugfix for infinite loop while handling chained exceptions that contain cycles Dec 2, 2022
Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

Looks good, I'd add another test.

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

LGTM.

@gpshead - as a maintainer of unittest, do you want to backport this?

@iritkatriel iritkatriel added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Dec 4, 2022
@gpshead gpshead added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Dec 4, 2022
@gpshead gpshead merged commit 72ec518 into python:main Dec 4, 2022
@miss-islington
Copy link
Contributor

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

@bedevere-bot
Copy link

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

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Dec 4, 2022
@bedevere-bot
Copy link

GH-99996 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Dec 4, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 4, 2022
…ined exceptions that contain cycles (pythonGH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 4, 2022
…ined exceptions that contain cycles (pythonGH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <[email protected]>
miss-islington added a commit that referenced this pull request Dec 4, 2022
…xceptions that contain cycles (GH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <[email protected]>
miss-islington added a commit that referenced this pull request Dec 4, 2022
…xceptions that contain cycles (GH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unittest: self-referencing explicit exception cause results in infinite loop
7 participants