Skip to content

Fix #2607: handle frozen dataclass exceptions - #3522

Closed
sb123sb123 wants to merge 1 commit into
python-trio:mainfrom
sb123sb123:oss-pr-200-2607-frozen-exception
Closed

sb123sb123 wants to merge 1 commit into
python-trio:mainfrom
sb123sb123:oss-pr-200-2607-frozen-exception

Conversation

@sb123sb123

@sb123sb123 sb123sb123 commented Sep 22, 2026

Copy link
Copy Markdown

Fixes #2607

When strict_exception_groups=False collapses a single exception group, Trio updates traceback and context metadata on the contained exception. Frozen dataclass exceptions reject normal attribute assignment, so the original exception is replaced by FrozenInstanceError.

This change uses object.__setattr__ for Trio internal traceback/context restoration paths and adds a regression test through a real nursery.

Testing:

  • PYTHONPATH=src .venv/Scripts/python.exe -m pytest src/trio/_core/_tests/test_run.py -q - 155 passed, 1 skipped
  • PYTHONPATH=src .venv/Scripts/python.exe -m pytest src/trio/_tests/test_util.py -q - 8 passed
  • .venv/Scripts/ruff.exe check src/trio/_core/_run.py src/trio/_core/_tests/test_run.py src/trio/_util.py - passed
  • python -m black --check src/trio/_core/_run.py src/trio/_core/_tests/test_run.py src/trio/_util.py - passed
  • Direct Windows reproduction with a frozen dataclass exception - returned the original FrozenError

A baseline run of src/trio/_core/_tests/test_io.py had 28 passed and 1 failure because this Windows host emits localized text for WinError 10038 while the existing test regex only accepts the English message; this is unrelated to the change.

AI assistance was used to investigate, implement, and test this patch. The reported results are from commands actually run on the Windows host.

@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (0480602) to head (4547a15).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3522   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19471        19483   +12     
  Branches         1323         1323           
===============================================
+ Hits            19471        19483   +12     
Files with missing lines Coverage Δ
src/trio/_core/_run.py 100.00000% <100.00000%> (ø)
src/trio/_core/_tests/test_run.py 100.00000% <100.00000%> (ø)
src/trio/_util.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@A5rocks

A5rocks commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Thanks, but I don't want to fix this. strict_exception_groups=False is deprecated and is due to be removed in a couple months. Besides, this is a behavior change. Maybe some exceptions rely on their custom __setattr__ in ways other than being frozen!

@A5rocks A5rocks closed this Sep 22, 2026
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.

collapse_exception_group breaks with exceptions that are also frozen dataclasses

2 participants