Skip to content

fix: Unbound raw reference in parse_message_update#2905

Merged
Lulalaby merged 5 commits into
Pycord-Development:masterfrom
Lumabots:UnboundLocalError-cannot-access-local-variable-'raw'-where-it-is-not-associated-with-a-value
Sep 3, 2025
Merged

fix: Unbound raw reference in parse_message_update#2905
Lulalaby merged 5 commits into
Pycord-Development:masterfrom
Lumabots:UnboundLocalError-cannot-access-local-variable-'raw'-where-it-is-not-associated-with-a-value

Conversation

@Lumabots

@Lumabots Lumabots commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Summary

Here’s a nicely formatted PR draft you can use for your change 👇


📖 Description

This PR fixes an issue in the parse_message_update method where the variable raw was being referenced before assignment when retrieving old_message.

Previously, the method tried to access raw.message_id before raw was defined, causing an unbound variable error.
Now, the method correctly retrieves the message ID directly from data["id"] before creating the RawMessageUpdateEvent.


🔧 Changes Made

  • Updated old_message retrieval to use int(data["id"]) instead of raw.message_id.
  • Ensured raw is created after both old_message and the new Message object are initialized.
  • Maintained existing event dispatch logic (raw_message_edit, message_edit, poll handling, and component tracking).

✅ Why This Fix Matters

  • Prevents runtime errors caused by referencing an uninitialized raw variable.
  • Ensures message updates are processed consistently.
  • Improves code clarity by keeping the order of operations correct.

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.

@Lumabots
Lumabots requested a review from a team as a code owner September 3, 2025 16:32
@pullapprove4
pullapprove4 Bot requested a review from BobDotCom September 3, 2025 16:32
@Lumabots Lumabots changed the title fix: unbound raw Fix: Unbound raw reference in parse_message_update Sep 3, 2025
@Lumabots Lumabots changed the title Fix: Unbound raw reference in parse_message_update fix: Unbound raw reference in parse_message_update Sep 3, 2025
@Paillat-dev

Copy link
Copy Markdown
Member

Changelog pls

@Lumabots
Lumabots requested review from a team as code owners September 3, 2025 16:45
Comment thread CHANGELOG.md Outdated
Signed-off-by: Paillat <[email protected]>
@plun1331

plun1331 commented Sep 3, 2025

Copy link
Copy Markdown
Member

Here’s a nicely formatted PR draft you can use for your change 👇

@Lulalaby
Lulalaby merged commit cbe9944 into Pycord-Development:master Sep 3, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants