-
-
Notifications
You must be signed in to change notification settings - Fork 484
fix: Prevent crashes from View.refresh
#3059
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
d1bb478
ed6b6e0
850edd6
242909d
da17564
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -360,7 +360,7 @@ def remove_item(self, item: InputText) -> Self: | |
| pass | ||
| return self | ||
|
|
||
| def refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
| def _refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
| components = [ | ||
| component | ||
| for parent_component in data | ||
|
|
@@ -444,7 +444,7 @@ def add_item(self, item: ModalItem) -> Self: | |
| super().add_item(item) | ||
| return self | ||
|
|
||
| def refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
| def _refresh(self, interaction: Interaction, data: list[ComponentPayload]): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| for component, child in zip(data, self.children): | ||
| child.refresh_from_modal(interaction, component) | ||
|
|
||
|
|
@@ -516,7 +516,7 @@ async def dispatch(self, user_id: int, custom_id: str, interaction: Interaction) | |
|
|
||
| try: | ||
| components = interaction.data["components"] | ||
| modal.refresh(interaction, components) | ||
| modal._refresh(interaction, components) | ||
| await modal.callback(interaction) | ||
| self.remove_modal(modal, user_id) | ||
| except Exception as e: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import logging | ||
| import os | ||
| import sys | ||
| import time | ||
|
|
@@ -75,6 +76,8 @@ | |
| from ..state import ConnectionState | ||
| from ..types.components import Component as ComponentPayload | ||
|
|
||
| _log = logging.getLogger(__name__) | ||
|
|
||
| V = TypeVar("V", bound="BaseView", covariant=True) | ||
|
|
||
|
|
||
|
|
@@ -726,7 +729,7 @@ def clear_items(self) -> None: | |
| self.__weights.clear() | ||
| return self | ||
|
|
||
| def refresh(self, components: list[Component]): | ||
| def _refresh(self, components: list[Component]): | ||
| # This is pretty hacky at the moment | ||
| old_state: dict[tuple[int, str], ViewItem[V]] = { | ||
| (item.type.value, item.custom_id): item for item in self.children if item.is_dispatchable() # type: ignore | ||
|
|
@@ -895,7 +898,7 @@ def add_item(self, item: ViewItem[V]) -> Self: | |
| super().add_item(item) | ||
| return self | ||
|
|
||
| def refresh(self, components: list[Component]): | ||
| def _refresh(self, components: list[Component]): | ||
| # Refreshes view data using discord's values | ||
| # Assumes the components and items are identical | ||
| if not components: | ||
|
|
@@ -996,4 +999,9 @@ def update_from_message(self, message_id: int, components: list[ComponentPayload | |
| # pre-req: is_message_tracked == true | ||
| view = self._synced_message_views[message_id] | ||
| components = [_component_factory(d, state=self._state) for d in components] | ||
| view.refresh(components) | ||
| try: | ||
| view._refresh(components) | ||
| except: | ||
| _log.warning( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure here whether we should prefer Alternatively we maybe could add a |
||
| f"Failed to refresh View {view} from Message {message_id} due to mismatched state. Items may not have complete data." | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it something different, like target, would be less confusing.