Skip to content

fix: AttributeError when fetching a message from a PartialMessageable that has a thread - #3309

Open
Paillat-dev wants to merge 14 commits into
masterfrom
fix/partial-messageable-fetch-thread
Open

Paillat-dev wants to merge 14 commits into
masterfrom
fix/partial-messageable-fetch-thread

Conversation

@Paillat-dev

Copy link
Copy Markdown
Member

Summary

When fetching a message that has a thread from a PartialMessageable we don't have a guild so it breaks with:

 AttributeError:'NoneType' object has no attribute 'get_thread'
[...]
# channel is a PartialMessageable
File "[...]" , line 142 , in _get_first_log_message
     return await channel.fetch_message(int(message_id_str))
File "discord/abc.py" , line 1799 , in fetch_message
     return self._state.create_message(channel=channel, data=data)
File "discord/state.py" , line 2056 , in create_message
     return Message(state=self, channel=channel, data=data)
File "discord/message.py" , line 1208 , in __init__
     self.thread = Thread(
File "discord/threads.py" , line 174 , in __init__
     self._from_data(data)
File "discord/threads.py" , line 212 , in _from_data
     if thread := self.guild.get_thread(self.id) and data.pop("_invoke_flag", False): 

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.
  • I have read the Contributing Guidelines.
  • AI Usage has been disclosed.
    • If AI has been used, I understand fully what the code does

@Paillat-dev
Paillat-dev requested review from a team and Soheab July 19, 2026 21:14
@Paillat-dev
Paillat-dev requested a review from a team as a code owner July 19, 2026 21:14
@github-project-automation github-project-automation Bot moved this to Todo in Pycord Jul 19, 2026
@pycord-app

pycord-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

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/3309/head:pr-3309
git checkout pr-3309

This pull request can be installed with:

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

@Paillat-dev Paillat-dev changed the title fix: Guard for None guild fix: AttributeError when fetching a message from a PartialMessageable that has a thread Jul 19, 2026
@Paillat-dev Paillat-dev added the bug Something isn't working label Jul 19, 2026
@Paillat-dev

Copy link
Copy Markdown
Member Author

(this would have been fixed by better typing smhhhhhhh)

vmphase
vmphase previously approved these changes Jul 21, 2026
@vmphase

vmphase commented Jul 21, 2026

Copy link
Copy Markdown
Member

Don't forget about the changelog.

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
@Dorukyum
Dorukyum enabled auto-merge (squash) August 22, 2026 13:09
Comment thread discord/message.py Resolved
Comment thread CHANGELOG.md Resolved
Paillat-dev and others added 2 commits September 2, 2026 15:08
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
vmphase
vmphase previously approved these changes Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Update thread construction to preserve the fetched payload instead of replacing it with potentially stale cached data.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Comment thread discord/message.py
Comment on lines +1211 to +1213
self.thread = guild.get_thread(int(thread_data["id"])) or Thread(
guild=guild, state=self._state, data=thread_data
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I remember doing this for a specific reason, I'll have to take a look

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a worthy note, Copilot is surprisingly right.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure but I believe the thread_data there is partial and since in theory we are supposed to have it always in sync I preferred that one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Paillat-dev is this resolved then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe at least leave a comment explaining

Signed-off-by: plun1331 <plun1331@gmail.com>

This branch has not been deployed

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

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

7 participants