From 932ed9ea9d7ccd0ec833984295405a5f028ad6cd Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 27 Dec 2017 13:06:03 +0100 Subject: [PATCH] Cast to input peer early on get input entity and close cursor --- telethon/tl/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telethon/tl/session.py b/telethon/tl/session.py index c19b37db..1e374a54 100644 --- a/telethon/tl/session.py +++ b/telethon/tl/session.py @@ -355,12 +355,13 @@ class Session: Raises ValueError if it cannot be found. """ - c = self._conn.cursor() if isinstance(key, TLObject): + key = utils.get_input_peer(key) if type(key).SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') return key key = utils.get_peer_id(key, add_mark=True) + c = self._conn.cursor() if isinstance(key, str): phone = utils.parse_phone(key) if phone: @@ -375,6 +376,7 @@ class Session: c.execute('select id, hash from entities where id=?', (key,)) result = c.fetchone() + c.close() if result: i, h = result # unpack resulting tuple i, k = utils.resolve_id(i) # removes the mark and returns kind