-
-
Notifications
You must be signed in to change notification settings - Fork 483
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 all commits
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 |
|---|---|---|
|
|
@@ -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.