diff --git a/aiogram/dispatcher/event/handler.py b/aiogram/dispatcher/event/handler.py index 6c2a5e57..8314c52b 100644 --- a/aiogram/dispatcher/event/handler.py +++ b/aiogram/dispatcher/event/handler.py @@ -61,7 +61,8 @@ class HandlerObject(CallableMixin): def __post_init__(self) -> None: super(HandlerObject, self).__post_init__() - if inspect.isclass(self.callback) and issubclass(self.callback, BaseHandler): # type: ignore + callback = inspect.unwrap(self.callback) + if inspect.isclass(callback) and issubclass(callback, BaseHandler): self.awaitable = True async def check(self, *args: Any, **kwargs: Any) -> Tuple[bool, Dict[str, Any]]: diff --git a/tests/test_dispatcher/test_handler/test_base.py b/tests/test_dispatcher/test_handler/test_base.py index 21063b62..48550702 100644 --- a/tests/test_dispatcher/test_handler/test_base.py +++ b/tests/test_dispatcher/test_handler/test_base.py @@ -1,11 +1,13 @@ import asyncio import datetime +from functools import wraps from typing import Any import pytest from aiogram import Bot from aiogram.api.types import Chat, Message, Update +from aiogram.dispatcher.event.handler import HandlerObject from aiogram.dispatcher.handler.base import BaseHandler @@ -56,3 +58,9 @@ class TestBaseClassBasedHandler: assert handler.event == event assert handler.update == update + + @pytest.mark.asyncio + async def test_wrapped_handler(self): + # wrap the handler on dummy function + handler = wraps(MyHandler)(lambda: None) + assert HandlerObject(handler).awaitable is True