Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Lazy Listener? #482

Open
sigJoe opened this issue Oct 1, 2021 · 2 comments
Open

Conditional Lazy Listener? #482

sigJoe opened this issue Oct 1, 2021 · 2 comments
Assignees
Milestone

Comments

@sigJoe
Copy link

sigJoe commented Oct 1, 2021

Is there a way to make it so that the lazy function triggers conditionally based on the ack response?

For example, I want my ack to do parameter validation and potentially reject the request. Right now, my solution is to have the lazy function run the same parameter validation as the ack function, but it seems a bit wasteful. I'd much rather the lazy function not get triggered at all in the scenario where the ack function returns errors to the user.

Reproducible in:

The slack_bolt version

slack-bolt==1.9.1

Python runtime version

Python 3.8.12

OS info

ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95
Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64

Steps to reproduce:

Run something like this:

def validate_the_stuff(ack, view):
    #errors = validate_inputs(view)
    errors = { "environment-select-block": "Nope" }
    if len(errors) > 0:
        ack(response_action="errors", errors=errors)
        return False
    else:
        ack(response_action="clear")

def do_the_thing(view):
    logging.error("You should not get this far")

app.view_submission('environment_select_submit')(
    ack=validate_the_stuff,
    lazy=[do_the_thing]
)

Expected result:

Don't do the thing if validation fails.

Actual result:

Does the thing even if validation fails.

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.

@seratch seratch added this to the 1.x milestone Oct 4, 2021
@seratch seratch self-assigned this Oct 4, 2021
@seratch
Copy link
Member

seratch commented Oct 4, 2021

Hi @SigniantJoe, thanks for writing in!

Unfortunately, there is no way to run lazy listeners based on the ack listener behavior. the current recommendation for your use case at this moment is to have the same validation in the beginning of the lazy listeners.

With that being said, we may consider adding a new configuration / mechanism to support this use case in a better way.

@sigJoe
Copy link
Author

sigJoe commented Oct 4, 2021

@seratch thank you for confirming the behaviour. I do think this would be a great enhancement, especially as sometimes we need to query external services or do relatively heavy validation

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

No branches or pull requests

2 participants