You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/Linux
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
fromslack_bolt.app.async_appimportAsyncAppclassMyCallableMiddleware:
asyncdef__call__(self, next_) ->None:
awaitnext_()
app=AsyncApp()
app.middleware(MyCallableMiddleware()) # this raises `ValueError: Async middleware function must be an async function`
Expected result:
AsyncApp.middleware accepts anyCallable[..., Awaitable[Any]] object, per signature.
seratch
changed the title
AsyncCustomMiddleware iscoroutinefunction check breaks func: Callable signature
A class with async "__call__" method fails to work as a middleware
Aug 21, 2024
Hi @chet-manley, thanks for reporting this issue. The built-in inspect library's behaviuor is a bit surprising, but it seems this scenario should be supported. I found a workaround on bolt-python side, so will come up with a pull request resolving it. Once it's merged, we will release a new patch release fixing the issue.
seratch
added a commit
to seratch/bolt-python
that referenced
this issue
Aug 21, 2024
(Filling out the following details about bugs will help us solve your issue sooner.)
Reproducible in:
The
slack_bolt
versionPython runtime version
OS info
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
Expected result:
AsyncApp.middleware
accepts anyCallable[..., 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 herehttps://github.com/slackapi/bolt-python/blob/main/slack_bolt/middleware/async_custom_middleware.py#L13
where the signature for
func
isCallable[..., Awaitable[Any]]
(which my middleware instance is).However,
inspect.iscoroutinefunction
is used to checkfunc
, which does not pass, as it checks for the existence ofCO_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.
The text was updated successfully, but these errors were encountered: