Skip to content

Conversation

@NeloBlivion
Copy link
Member

@NeloBlivion NeloBlivion commented Jan 7, 2026

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_UPDATE from Discord and attempt to internally refresh the view before ViewStore has updated.

Traceback (most recent call last):
...
  File "/.../lib/python3.12/site-packages/discord/state.py", line 795, in parse_message_update
    self._view_store.update_from_message(raw.message_id, data["components"])
  File "/.../lib/python3.12/site-packages/discord/ui/view.py", line 807, in update_from_message
    view.refresh(components)
  File "/.../lib/python3.12/site-packages/discord/ui/view.py", line 610, in refresh
    item.refresh_component(c)
  File "/.../lib/python3.12/site-packages/discord/ui/container.py", line 371, in refresh_component
    x.refresh_component(y)
  File "/.../lib/python3.12/site-packages/discord/ui/section.py", line 268, in refresh_component
    for x, y in zip(self.items, component.components):
                                ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TextDisplay' object has no attribute 'components'
# The client received a TextDisplay where it was expecting a Section, because that was the structure of the OLD view.

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 relevant message_id beforehand.

This PR:

  • Attempts to refresh using the internal _original_response that's now returned from all interactions
  • If the refresh fails, be less distruptive with logging.warning
  • Renames refresh to reduce likelihood of being overridden by users

I'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

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@NeloBlivion NeloBlivion requested a review from a team as a code owner January 7, 2026 06:13
@pycord-app
Copy link

pycord-app bot commented Jan 7, 2026

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/3059/head:pr-3059
git checkout pr-3059

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3059/head

@Paillat-dev Paillat-dev added this to the v2.7.1 milestone Jan 7, 2026
@Paillat-dev Paillat-dev added hold: testing This pull request requires further testing components Related to discord components (Views + Modals) labels Jan 7, 2026
@Paillat-dev Paillat-dev self-requested a review January 7, 2026 10:38
@Paillat-dev Paillat-dev added the hold: changelog This pull request is missing a changelog entry label Jan 7, 2026
Copy link
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

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

(I am nitpicking, pr lgtm di per se)

try:
view._refresh(components)
except:
_log.warning(
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

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.

@Paillat-dev
Copy link
Member

Oh and changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components Related to discord components (Views + Modals) hold: changelog This pull request is missing a changelog entry hold: testing This pull request requires further testing PA: All Contributors pending

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants