Assistant listener middleware crashes when given a plain function

未关闭
#1,597 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@sahiljagtap08 已经在做这个了。

开始于 2026年10月8日。

  • #1591 来自 @sahiljagtap08 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

The bug is in Assistant.build_listener in slack_bolt/middleware/assistant/assistant.py and its async twin in async_assistant.py, which treat every middleware item as a Middleware instance and also mutate the caller's list with insert(0, ...). Compare with how App wraps plain functions in CustomMiddleware. Done when plain functions work as assistant middleware and the caller's list is left unchanged, with sync and async tests. A linked PR (#1591) already contains this fix, so check it before starting.

由索引模型根据 Issue 内容生成。

描述

auto-triage-stale
Reproducible in:
The slack_bolt version
slack_bolt==1.30.0
slack_sdk==3.45.0
Python runtime version
Python 3.12.5
OS info
macOS 27.0
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)
  1. Register the listener above.
  2. 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.

主要语言
Python
星标
1.3k
派生
300
平均合并
19 小时 33 分钟
30 天内合并 PR
25

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

slackapi/bolt-python 的其他 Issue

查看 slackapi/bolt-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。