From 272322ab382f16a64bca38b098a825d89cff70b2 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 11 May 2018 02:24:57 +0300 Subject: [PATCH] Fixed slow-responses into webhook (via simple request) --- aiogram/dispatcher/webhook.py | 7 +++++-- aiogram/utils/context.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/aiogram/dispatcher/webhook.py b/aiogram/dispatcher/webhook.py index 1711bffe..ca717202 100644 --- a/aiogram/dispatcher/webhook.py +++ b/aiogram/dispatcher/webhook.py @@ -87,8 +87,11 @@ class WebhookRequestHandler(web.View): :return: :class:`aiogram.Dispatcher` """ dp = self.request.app[BOT_DISPATCHER_KEY] - context.set_value('dispatcher', dp) - context.set_value('bot', dp.bot) + try: + context.set_value('dispatcher', dp) + context.set_value('bot', dp.bot) + except RuntimeError: + pass return dp async def parse_update(self, bot): diff --git a/aiogram/utils/context.py b/aiogram/utils/context.py index ea922b48..376d9aa9 100644 --- a/aiogram/utils/context.py +++ b/aiogram/utils/context.py @@ -46,6 +46,8 @@ def get_current_state() -> typing.Dict: :rtype: :obj:`dict` """ task = asyncio.Task.current_task() + if task is None: + raise RuntimeError('Can be used only in Task context.') context_ = getattr(task, 'context', None) if context_ is None: context_ = task.context = {}