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

Skip to content

Fix selectors when the onselect callback raises - #32349

Open
twelfthlabor wants to merge 1 commit into
matplotlib:mainfrom
twelfthlabor:fix/spanselector-callback-exception-state
Open

Fix selectors when the onselect callback raises#32349
twelfthlabor wants to merge 1 commit into
matplotlib:mainfrom
twelfthlabor:fix/spanselector-callback-exception-state

Conversation

@twelfthlabor

@twelfthlabor twelfthlabor commented Sep 13, 2026

Copy link
Copy Markdown

_SelectorWidget.release cleared _eventpress and _eventrelease only after self._release(event) returned, but _release is what calls the user's onselect callback. If that callback raised, the cleanup was skipped, and the stale _eventpress made ignore() stop rejecting events outside the selector's Axes. The failed selector then kept reacting to later interactions, including events meant for another selector.

Move the cleanup into a finally block so the exception still propagates while the selector stays usable afterwards. This covers all _SelectorWidget subclasses, which all call onselect from _release.

Fixes #32327.

AI Disclosure

I used an AI coding assistant to help implement this change and write the tests. I reviewed the diff and verified the behavior locally.

@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

`_SelectorWidget.release` cleared `_eventpress` and `_eventrelease` only
after `self._release(event)` returned, but `_release` is what calls the
user's `onselect` callback.  If that callback raised, the cleanup was
skipped, and the stale `_eventpress` made `ignore` stop rejecting events
outside the selector's Axes.  The failed selector then kept reacting to
later interactions, including events meant for another selector.

Move the cleanup into a `finally` block so the exception still propagates
while the selector stays usable afterwards.  This covers all
`_SelectorWidget` subclasses, which all call `onselect` from `_release`.

Fixes matplotlib#32327.
@twelfthlabor
twelfthlabor force-pushed the fix/spanselector-callback-exception-state branch from 8d69460 to 9b9dacf Compare September 13, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: exception raised in SpanSelector callback puts the selector in an invalid state for later interactions

1 participant