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

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

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

bedevere-bot commented Oct 19, 2022

Most changes to Python require a NEWS entry.

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

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Oct 19, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@zware zware left a comment

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

kumaraditya303
kumaraditya303 previously requested changes Nov 27, 2022
Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

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

@bedevere-bot
Copy link

bedevere-bot commented Nov 27, 2022

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

bedevere-bot commented Dec 1, 2022

Thanks for making the requested changes!

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

@bedevere-bot bedevere-bot requested a review from kumaraditya303 Dec 1, 2022
@kumaraditya303 kumaraditya303 requested a review from iritkatriel Dec 2, 2022
@kumaraditya303 kumaraditya303 dismissed their stale review Dec 2, 2022

test added

@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

Looks good, I'd add another test.

Lib/test/test_unittest/test_result.py Outdated Show resolved Hide resolved
Lib/test/test_unittest/test_result.py Show resolved Hide resolved
Lib/unittest/result.py Outdated Show resolved Hide resolved
Copy link
Member

@iritkatriel iritkatriel left a comment

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 approved these changes Dec 4, 2022
@gpshead gpshead merged commit 72ec518 into python:main Dec 4, 2022
15 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Dec 4, 2022

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

bedevere-bot commented Dec 4, 2022

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

@bedevere-bot
Copy link

bedevere-bot commented Dec 4, 2022

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

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 <0xalextate@gmail.com>
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 <0xalextate@gmail.com>
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 <0xalextate@gmail.com>
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 <0xalextate@gmail.com>
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