Skip to content

Unmatched message listener middleware can be called #232

Description

@Beartime234

I'm not sure if this is intended or not but it doesn't really seem like it. It looks like middleware is shared between listeners of the same type.

Reproducible in:

import os

from slack_bolt import App

app = App(
    token=os.environ.get("SLACK_BOT_TOKEN"),
    signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)


def test_middleware(logger, next):
    logger.critical("We ran this middleware")
    next()


@app.message("one", middleware=[test_middleware])
def one():
    return


@app.message("two", middleware=[])
def two():
    return


def main():
    app.start(port=int(os.environ.get("PORT", 3000)))


if __name__ == "__main__":
    main()

The slack_bolt version

slack-bolt==1.3.0
slack-sdk==3.3.0

Python runtime version

Python 3.8.3

OS info

ProductName: Mac OS X
ProductVersion: 10.15.7
BuildVersion: 19H2
Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., setup.py))

  1. Start up the app
  2. Type one into slack
  3. You will see in the logs that it will run test_middleware by logging "We ran this middleware"
  4. Type two into slack
  5. You will see in the logs that that it will run test_middleware by logging "We ran this middleware"

Expected result:

The middleware test_middleware will only run when the user types in one as that has specified that middleware and two
has not specified that middleware

Actual result:

The middleware will on both listeners as you can see it logs from both message listeners.

I have also noted if that you switch the order of them and load the first listener in without the middleware this issue will not happen. It seems to be saving it and or not resetting the middleware.

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.

Activity

  1. added this to the 1.3.1 milestone on Feb 7, 2021
  2. self-assigned this
    on Feb 7, 2021
  3. seratch commented on Feb 7, 2021

    @seratch
    Contributor

    Hi @Beartime234, thanks a lot for taking the time to report this issue. You are right. This is an obvious bug introduced by my pull request #41 - I will send a pull request to resolve this issue shortly and we'll make a patch release including the fix.

  4. changed the title [-]Middleware running for repeated message listeners[/-] [+]Unmatched message listener middleware can be called[/+] on Feb 7, 2021
  5. Beartime234 commented on Feb 9, 2021

    @Beartime234
    Author

    Thanks so much for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions