-
Notifications
You must be signed in to change notification settings - Fork 275
Description
(Filling out the following details about bugs will help us solve your issue sooner.)
Reproducible in:
pip freeze | grep slack
python --version
sw_vers && uname -v # or `ver`The slack_bolt version
slack-bolt==1.18.1
slack_sdk==3.31.0Python runtime version
Python 3.11.9OS info
bash: sw_vers: command not found
❯ uname -a
Linux 49d1cffcb728 6.8.4-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 4 20:45:21 UTC 2024 x86_64 x86_64 x86_64 GNU/LinuxSteps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
from slack_bolt.app.async_app import AsyncApp
class MyCallableMiddleware:
async def __call__(self, next_) -> None:
await next_()
app = AsyncApp()
app.middleware(MyCallableMiddleware()) # this raises `ValueError: Async middleware function must be an async function`Expected result:
AsyncApp.middleware accepts any Callable[..., Awaitable[Any]] object, per signature.
Actual result:
The middleware instance pass the callable check here
https://github.com/slackapi/bolt-python/blob/main/slack_bolt/app/async_app.py#L678
and is thus sent to AsyncCustomMiddleware init here
https://github.com/slackapi/bolt-python/blob/main/slack_bolt/middleware/async_custom_middleware.py#L13
where the signature for func is Callable[..., Awaitable[Any]] (which my middleware instance is).
However, inspect.iscoroutinefunction is used to check func, which does not pass, as it checks for the existence of
CO_COROUTINE flag (see here: CPython source),
despite the instance being both callable and asynchronous.
Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.