From 1fb3d0d00cf8c778b7b483ba54614ee360f9946a Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 5 Oct 2017 13:14:54 +0200 Subject: [PATCH] Fix EntityDatabase failing to cache self user --- telethon/tl/entity_database.py | 4 ++-- telethon/utils.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/telethon/tl/entity_database.py b/telethon/tl/entity_database.py index ee2c5b67..ce25a6e0 100644 --- a/telethon/tl/entity_database.py +++ b/telethon/tl/entity_database.py @@ -66,7 +66,7 @@ class EntityDatabase: continue try: - p = utils.get_input_peer(e) + p = utils.get_input_peer(e, allow_self=False) new_input[utils.get_peer_id(p, add_mark=True)] = \ getattr(p, 'access_hash', 0) # chats won't have hash @@ -93,7 +93,7 @@ class EntityDatabase: "full" means simply not "Input*". """ marked_id = utils.get_peer_id( - utils.get_input_peer(entity), add_mark=True + utils.get_input_peer(entity, allow_self=False), add_mark=True ) try: old_entity = self._entities[marked_id] diff --git a/telethon/utils.py b/telethon/utils.py index e021af03..74fbb90d 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -72,7 +72,7 @@ def _raise_cast_fail(entity, target): .format(type(entity).__name__, target)) -def get_input_peer(entity): +def get_input_peer(entity, allow_self=True): """Gets the input peer for the given "entity" (user, chat or channel). A ValueError is raised if the given entity isn't a supported type.""" if not isinstance(entity, TLObject): @@ -82,7 +82,7 @@ def get_input_peer(entity): return entity if isinstance(entity, User): - if entity.is_self: + if entity.is_self and allow_self: return InputPeerSelf() else: return InputPeerUser(entity.id, entity.access_hash) @@ -312,7 +312,7 @@ def get_peer_id(peer, add_mark=False): if type(peer).SUBCLASS_OF_ID not in {0x2d45687, 0xc91c90b6}: # Not a Peer or an InputPeer, so first get its Input version - peer = get_input_peer(peer) + peer = get_input_peer(peer, allow_self=False) if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser): return peer.user_id