From 980f8b32fc16ff1ec6708b93fd1f923b8c684c3d Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 5 May 2023 00:04:30 +0200 Subject: [PATCH] Fix KeyError when ID is in cache but queried without mark Closes #4084. --- telethon/client/users.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/telethon/client/users.py b/telethon/client/users.py index ab05ece2..e2587a13 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -316,7 +316,9 @@ class UserMethods: # Merge users, chats and channels into a single dictionary id_entity = { - utils.get_peer_id(x): x + # `get_input_entity` might've guessed the type from a non-marked ID, + # so the only way to match that with the input is by not using marks here. + utils.get_peer_id(x, add_mark=False): x for x in itertools.chain(users, chats, channels) } @@ -329,7 +331,7 @@ class UserMethods: if isinstance(x, str): result.append(await self._get_entity_from_string(x)) elif not isinstance(x, types.InputPeerSelf): - result.append(id_entity[utils.get_peer_id(x)]) + result.append(id_entity[utils.get_peer_id(x, add_mark=False)]) else: result.append(next( u for u in id_entity.values()