Skip to content

[PR #14220/680f9f3e backport][9.1.x] raises: fix stale loop variable in RaisesGroup error reporting#14620

Merged
bluetech merged 1 commit into
9.1.xfrom
patchback/backports/9.1.x/680f9f3ed3faaaa9a4fd1d8120618cd17cdee2d0/pr-14220
Jun 17, 2026
Merged

[PR #14220/680f9f3e backport][9.1.x] raises: fix stale loop variable in RaisesGroup error reporting#14620
bluetech merged 1 commit into
9.1.xfrom
patchback/backports/9.1.x/680f9f3ed3faaaa9a4fd1d8120618cd17cdee2d0/pr-14220

Conversation

@patchback

@patchback patchback Bot commented Jun 17, 2026

Copy link
Copy Markdown

This is a backport of PR #14220 as merged into main (680f9f3).

In RaisesGroup._check_exceptions, the diagnostic section that builds failure messages for unmatched expected exceptions has a bug on this line:

for i_failed in failed_expected:
    s += (
        f"\n{indent_1}{self._repr_expected(self.expected_exceptions[i_failed])}"
    )
    for i_actual, actual in enumerate(actual_exceptions):
        if results.get_result(i_exp, i_actual) is None:  # <-- bug

i_exp here is a leftover from the earlier for i_exp, expected in enumerate(self.expected_exceptions): loop that computes the full results matrix. By the time we reach this diagnostic loop, i_exp holds whatever value it had when that earlier loop finished -- it doesn't track the current i_failed iteration at all.

This means the results.get_result(i_exp, i_actual) call looks up the wrong expected exception's result, so the "It matches ... which was paired with ..." hints in the failure output can be completely wrong or missing.

Fix: replace i_exp with i_failed, which is the actual loop variable for the current expected exception being reported.

raises: fix stale loop variable in RaisesGroup error reporting
(cherry picked from commit 680f9f3)
@bluetech bluetech merged commit ef8b299 into 9.1.x Jun 17, 2026
36 checks passed
@bluetech bluetech deleted the patchback/backports/9.1.x/680f9f3ed3faaaa9a4fd1d8120618cd17cdee2d0/pr-14220 branch June 17, 2026 14:56
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.

1 participant