Skip to content
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

Fix KeyError when user(64-bit ID) send a message to himself #843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zankoAn
Copy link

@zankoAn zankoAn commented Dec 31, 2021

When a new client user(64-bit ID) tries to send himself a message like this:

app.send_message("me", "Test")

He receives an Key Error .

The message is sent successfully but the code is broken and this error occurs.

Details:

Traceback (most recent call last):
  File "/home/zanko/.local/lib/python3.9/site-packages/pyrogram/dispatcher.py", line 217, in handler_worker
    await handler.callback(self.client, *args)
  File "/home/zanko/Videos/move2020/Animi/ranger war/create_session/test1/33.py", line 20, in x
    await app.send_message("me", "Test")
  File "/home/zanko/.local/lib/python3.9/site-packages/pyrogram/methods/messages/send_message.py", line 170, in send_message
    return await types.Message._parse(
  File "/home/zanko/.local/lib/python3.9/site-packages/pyrogram/types/messages_and_media/message.py", line 677, in _parse
    sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
  File "/home/zanko/.local/lib/python3.9/site-packages/pyrogram/types/user_and_chats/chat.py", line 253, in _parse
    return Chat._parse_user_chat(client, users[chat_id])
KeyError: 5068773474

This error happen because raw method raw.functions.messages.SendMessage doesn't return full update means users field is empty :

    "users": [],
    "chats": [],
    "date": 1640900272,
    "seq": 0

And when it reaches the _parse function in types/messages_and_media/message.py message.from_id return the None value, then this condition doesn't execute:

if isinstance(message.from_id, raw.types.PeerUser) and isinstance(message.peer_id, raw.types.PeerUser)

Finally, users dictionary is not updated(within the condition) and as you can see in the error, there is no key for chat_id inside users.

@DavideGalilei
Copy link
Contributor

This is no longer required, since Pyrogram currently supports int64 user ids.

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

Successfully merging this pull request may close these issues.

None yet

2 participants