Skip to content

Fix disconnection of callbacks when draggable artist is deparented. #25442

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

Merged
merged 1 commit into from
Mar 14, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 12, 2023

Once a draggable artist has been removed from its parent figure, we cannot access self.canvas (i.e. a property for
self.ref_artist.figure.canvas) anymore to disconnect the relevant callbacks. Instead, we should keep track from the very beginning (in the DraggableBase constructor) of the place from which the callbacks should be disconnected.

Closes #25440.

Release critical as it's a regression due to #25311.

PR Summary

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Once a draggable artist has been removed from its parent figure, we
cannot access `self.canvas` (i.e. a property for
`self.ref_artist.figure.canvas`) anymore to disconnect the relevant
callbacks.  Instead, we should keep track from the very beginning (in
the DraggableBase constructor) of the place from which the callbacks
should be disconnected.
@anntzer anntzer added this to the v3.7.2 milestone Mar 12, 2023
@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Mar 12, 2023
self.canvas.callbacks._connect_picklable(
'button_release_event', self.on_release),
callbacks = ref_artist.figure._canvas_callbacks
self._disconnectors = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to drop this in __getstate__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canvas property has a note "property not attribute to keep pickable" which I understood to be because pickling the canvas was not always safe and this includes a reference to the canvas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reference to the canvas, only to the figure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦🏻 I can not read (I was reading ref_artist.figure.canvas.callbacks) and forget we moved the callback registry to live on the figure.

@ksunden ksunden merged commit 370547e into matplotlib:main Mar 14, 2023
@lumberbot-app
Copy link

lumberbot-app bot commented Mar 14, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 370547ebfc12e879aefe0f914eaa94d72eb95a9b
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #25442: Fix disconnection of callbacks when draggable artist is deparented.'
  1. Push to a named branch:
git push YOURFORK v3.7.x:auto-backport-of-pr-25442-on-v3.7.x
  1. Create a PR against branch v3.7.x, I would have named this PR:

"Backport PR #25442 on branch v3.7.x (Fix disconnection of callbacks when draggable artist is deparented.)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@anntzer anntzer deleted the rd branch March 14, 2023 21:46
ksunden added a commit to ksunden/matplotlib that referenced this pull request Mar 14, 2023
Fix disconnection of callbacks when draggable artist is deparented.

(cherry picked from commit 370547e)
@QuLogic
Copy link
Member

QuLogic commented Mar 14, 2023

Backport in #25465.

oscargus added a commit that referenced this pull request Mar 15, 2023
…3.7.x

Backport PR #25442 on branch v3.7.x (Fix disconnection of callbacks when draggable artist is deparented.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Attribute Error combining matplotlib 3.7.1 and mplcursor on data selection
4 participants