From b3990546eb1bc950d8f17d100887c9ff359d65b0 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 25 Jul 2018 12:19:28 +0200 Subject: [PATCH] Fix RPCError may occur for no parent message (#908) --- telethon/network/mtprotosender.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 481dd974..4a3a38b7 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -512,6 +512,12 @@ class MTProtoSender: __log__.debug('Handling RPC result for message %d', rpc_result.req_msg_id) + if not message: + # TODO We should not get responses to things we never sent + __log__.info('Received response without parent request: {}' + .format(rpc_result.body)) + return + if rpc_result.error: error = rpc_message_to_error(rpc_result.error) self._send_queue.put_nowait(self.state.create_message( @@ -520,8 +526,7 @@ class MTProtoSender: if not message.future.cancelled(): message.future.set_exception(error) - return - elif message: + else: # TODO Would be nice to avoid accessing a per-obj read_result # Instead have a variable that indicated how the result should # be read (an enum) and dispatch to read the result, mostly @@ -531,11 +536,6 @@ class MTProtoSender: if not message.future.cancelled(): message.future.set_result(result) - return - else: - # TODO We should not get responses to things we never sent - __log__.info('Received response without parent request: {}' - .format(rpc_result.body)) async def _handle_container(self, message): """