Reproducible in:
The slack_bolt version
slack_bolt==1.30.0
slack_sdk==3.45.0
Python runtime version
OS info
Steps to reproduce:
Pass a plain function as listener middleware on an Assistant listener.
from slack_bolt import App, Assistant
app = App(token="xoxb-...", signing_secret="secret")
assistant = Assistant()
def my_middleware(next):
next()
@assistant.user_message(middleware=[my_middleware])
def handle(say):
say("hi")
app.use(assistant)
- Register the listener above.
- Send a user message in an assistant thread.
Expected result:
The function is accepted as middleware, the same way @app.event(..., middleware=[my_middleware]) accepts it.
Actual result:
Every matching event fails with AttributeError: 'function' object has no attribute 'process'.
Assistant.build_listener in slack_bolt/middleware/assistant/assistant.py (and AsyncAssistant in async_assistant.py) treats every item in middleware as a Middleware instance. App wraps plain functions in CustomMiddleware, but the assistant does not. It also calls middleware.insert(0, ...) on the list the caller passed in, so the caller's list is changed.
I have a fix with sync and async tests in #1591.
Requirements
I have read the Contributing guidelines and Code of Conduct.
Reproducible in:
The
slack_boltversionPython runtime version
OS info
Steps to reproduce:
Pass a plain function as listener middleware on an
Assistantlistener.Expected result:
The function is accepted as middleware, the same way
@app.event(..., middleware=[my_middleware])accepts it.Actual result:
Every matching event fails with
AttributeError: 'function' object has no attribute 'process'.Assistant.build_listenerinslack_bolt/middleware/assistant/assistant.py(andAsyncAssistantinasync_assistant.py) treats every item inmiddlewareas aMiddlewareinstance.Appwraps plain functions inCustomMiddleware, but the assistant does not. It also callsmiddleware.insert(0, ...)on the list the caller passed in, so the caller's list is changed.I have a fix with sync and async tests in #1591.
Requirements
I have read the Contributing guidelines and Code of Conduct.