fix: Prevent crashes from View.refresh#3059
fix: Prevent crashes from View.refresh#3059NeloBlivion wants to merge 5 commits intoPycord-Development:masterfrom
View.refresh#3059Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3059/head:pr-3059
git checkout pr-3059This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3059/head |
Paillat-dev
left a comment
There was a problem hiding this comment.
(I am nitpicking, pr lgtm di per se)
| try: | ||
| view._refresh(components) | ||
| except: | ||
| _log.warning( |
There was a problem hiding this comment.
I'm not sure here whether we should prefer _log.warning or _log.exception - with the reasoning behind this being that this potentially removes from existence useful traceback info in case someone encounters this when they should not.
Alternatively we maybe could add a _log.debug with exc_info=True as well or something ? Idk just an idea.
| ) | ||
| if view and self.message: | ||
| self._state.prevent_view_updates_for(self.message.id) | ||
| _message = self.message or self._original_response |
There was a problem hiding this comment.
Maybe call it something different, like target, would be less confusing.
|
Oh and changelog |
| return self | ||
|
|
||
| def refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
| def _refresh(self, interaction: Interaction, data: list[ComponentPayload]): |
There was a problem hiding this comment.
I'd add an overrideable alias from refresh to _refresh with a deprecation warning, although it's not strictly necessary, I'm sure some people used this method for whatever reason, and while it wasn't documented, it was in fact private.
There was a problem hiding this comment.
Because it wasn't documented I don't think a deprecation warning is necessary.
|
@Lumabots Can you run your test bot on this pr for some time or something like that ? |
yep |
|
@Lumabots You tested using views and stuff ? |
Yep, using view, timeout, persistent view replace item add item remove item etc |
|
In case you missed it @NeloBlivion I left a couple comments here |
| return self | ||
|
|
||
| def refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
| def _refresh(self, interaction: Interaction, data: list[ComponentPayload]): |
There was a problem hiding this comment.
Because it wasn't documented I don't think a deprecation warning is necessary.
| _message = self.message or self._original_response | ||
| if view and _message: | ||
| self._state.prevent_view_updates_for(_message.id) |
There was a problem hiding this comment.
I agree with Paillat
| _message = self.message or self._original_response | |
| if view and _message: | |
| self._state.prevent_view_updates_for(_message.id) | |
| _target = self.message or self._original_response | |
| if view and _target: | |
| self._state.prevent_view_updates_for(_target.id) |
Summary
Pycord currently has an issue with race conditions in views - sometimes when editing a message or interaction response, the gateway will receive said message's
MESSAGE_UPDATEfrom Discord and attempt to internallyrefreshthe view beforeViewStorehas updated.This is meant to be circumvented through
remove_message_tracking, but this is not possible in response edit scenarios where the library may not have knowledge of the relevantmessage_idbeforehand.This PR:
_original_responsethat's now returned from all interactionslogging.warningI'm not certain if the first change is entirely appropriate - if this happens to target the wrong message, I will instead revert that specfic change.
Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.