Skip to content

Conversation

@leiyi2000
Copy link
Contributor

@leiyi2000 leiyi2000 commented Jun 16, 2025

Summary

Fixed a RecursionError when logging re-raised exceptions from an ExceptionGroup in Python 3.11 and above (#726). The fix adds a version check and detects when the exception cause is an ExceptionGroup, preventing further recursive traversal of the exception chain, which previously led to infinite recursion.

Pull Request Check List

  • Do not open pull requests from your main branch – use a separate branch!
    • There's a ton of footguns waiting if you don't heed this warning. You can still go back to your project, create a branch from your main branch, push it, and open the pull request from the new branch.
    • This is not a pre-requisite for your pull request to be accepted, but you have been warned.
  • Added tests for changed code.
    • The CI fails with less than 100% coverage.
  • New APIs are added to our typing tests in api.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
      • The next version is the second number in the current release + 1. The first number represents the current year. So if the current version on PyPI is 23.1.0, the next version is gonna be 23.2.0. If the next version is the first in the new year, it'll be 24.1.0.
  • Documentation in .rst and .md files is written using semantic newlines.
  • Changes (and possible deprecations) are documented in the changelog.
  • Consider granting push permissions to the PR branch, so maintainers can fix minor issues themselves without pestering you.

@hynek
Copy link
Owner

hynek commented Jun 16, 2025

@sscherfke 😇

@sscherfke
Copy link
Contributor

lgtm :)

@sscherfke
Copy link
Contributor

Maybe we could create a _compat module with constants for Python versions like I did here. Would make it easier to find these occurances and remove them when a Python versions gets unsupported.

@leiyi2000
Copy link
Contributor Author

Maybe we could create a _compat module with constants for Python versions like I did here. Would make it easier to find these occurances and remove them when a Python versions gets unsupported.

I've reviewed the implementation in _compat module , but checking Python version ranges (e.g., ensuring the version is between 3.9 and 3.11) becomes quite cumbersome with this approach.

@leiyi2000
Copy link
Contributor Author

Perhaps all we need is just a constant to indicate whether the current Python version supports ExceptionGroup.

@hynek
Copy link
Owner

hynek commented Jun 20, 2025

The problem with all these constants instead of straight version checks is – last time I checked – that they're not supported by Mypy and you'll get weird errors about undefined symbols etc. Not sure if that changed?

@sscherfke
Copy link
Contributor

Then let's keep the PR as it is.

The "python version checking" issue is unrelated to the issue that this PR addresses.

@leiyi2000 leiyi2000 changed the title fix RecursionError when logging re-raised Exception from an ExceptionGroup #726 fix RecursionError when logging re-raised Exception from an ExceptionGroup Jun 28, 2025
@hynek hynek mentioned this pull request Jul 23, 2025
@hynek
Copy link
Owner

hynek commented Sep 11, 2025

hopefully fixed by #739 with credit to you – sorry for the delays

@hynek hynek closed this Sep 11, 2025
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.

3 participants