Fix channel/chat IDs being misinterpreted as user IDs#90
Open
embogomolov wants to merge 1 commit intochigwell:mainfrom
Open
Fix channel/chat IDs being misinterpreted as user IDs#90embogomolov wants to merge 1 commit intochigwell:mainfrom
embogomolov wants to merge 1 commit intochigwell:mainfrom
Conversation
Telethon internally uses unmarked IDs (positive integers) for channels
and chats. When these IDs are returned to callers and later passed back
to get_entity(int), Telethon interprets positive ints as PeerUser,
causing ValueError ("Could not find the input entity for PeerUser").
Add get_marked_id() helper that converts:
- Channel -> -100{id} (PeerChannel format)
- Chat -> -{id} (PeerChat format)
- User -> id (unchanged)
Apply it in all places where entity IDs are returned: list_chats,
get_chats, get_chat, format_entity, get_direct_chat_by_contact,
get_contact_chats, create_group, get_bot_info, get_folder.
Author
|
Anyone? |
Owner
|
Hey @embogomolov, thank you for the contribution! Could I please ask you to fix the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
Telethon uses unmarked IDs internally — positive integers for everything. When the server returns these raw IDs to callers (say, from
list_chats), and the caller passes them back intoget_entity(int), Telethon sees a positive number and assumes it's a user. Channels and group chats get aValueError: Could not find the input entity for PeerUser.Any "list chats → pick one → do something" workflow breaks intermittently, especially after long sessions when entity cache expires.
The fix
get_marked_id()helper that converts entity IDs to Telethon's marked format before returning:-100{id}(PeerChannel)-{id}(PeerChat)Applied in all places where entity IDs go out to callers:
list_chats,get_chats,get_chat,format_entity,get_direct_chat_by_contact,get_contact_chats,create_group,get_bot_info,get_folder.How to test
list_chats, grab a channel ID, pass it tosearch_messagesorget_history— should work without errors-1001676885811instead of1676885811