From ef1cb6a089bd84b53bb40f294f5f8b2e3c28c96a Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 23 Feb 2026 02:30:05 -0500 Subject: [PATCH] Prevent empty dictionaries from being added to the ViewStore Fix #10405 --- discord/ui/view.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index ed105b5d6..8dc6b01aa 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -899,7 +899,7 @@ class ViewStore: self._modals[view.custom_id] = view # type: ignore return - dispatch_info = self._views.setdefault(message_id, {}) + dispatch_info = self._views.get(message_id, {}) is_fully_dynamic = True for item in view.walk_children(): if isinstance(item, DynamicItem): @@ -910,6 +910,9 @@ class ViewStore: is_fully_dynamic = False view._cache_key = message_id + if dispatch_info: + self._views[message_id] = dispatch_info + if message_id is not None and not is_fully_dynamic: self._synced_message_views[message_id] = view @@ -927,8 +930,8 @@ class ViewStore: elif item.is_dispatchable(): dispatch_info.pop((item.type.value, item.custom_id), None) # type: ignore - if len(dispatch_info) == 0: - self._views.pop(view._cache_key, None) + if dispatch_info is not None and len(dispatch_info) == 0: + self._views.pop(view._cache_key, None) self._synced_message_views.pop(view._cache_key, None) # type: ignore