Assistant listener middleware crashes when given a plain function

Offen
#1,597 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@sahiljagtap08 arbeitet bereits daran.

Seit 08.10.2026.

  • #1591 von @sahiljagtap08 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
30/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
1.3k
Forks
300
Ø Merge
19 Std. 33 Min.
Gemergte PRs (30 T.)
25

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus slackapi/bolt-python

Alle Issues in slackapi/bolt-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.