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

fix: Disable validation without making check.disable() async #10

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

gadenbuie
Copy link
Contributor

@gadenbuie gadenbuie commented Jan 8, 2025

Fixes #8
Closes #9

The issue in #8 arises because InputValidator.disable() calls the async session.send_custom_message() without awaiting.

One option would be to declare the .disable() method async, but this would be a breaking change in the sense that app authors would need to update their apps to mark any callers of .disable() as async and then await the disable call.

I don't think this is worth the collective effort; instead we can simply fire off the disabling message, which only affects UI elements in the app. This PR does exactly that: we fire-and-forget the custom message, leaving .disable() "synchronous".

Example app

from shiny import App, Inputs, Outputs, Session, reactive, ui

from shiny_validate import InputValidator, check

app_ui = ui.page_fluid(
    ui.input_text("email_address", "Email Address"),
    ui.input_action_button("disable", "Disable"),
)


def server(input: Inputs, output: Outputs, session: Session):
    iv = InputValidator()
    iv.add_rule("email_address", check.required())
    iv.add_rule("email_address", check.email())

    iv.enable()
    enabled = reactive.value(True)

    @reactive.effect
    @reactive.event(input.disable)
    def _():
        if enabled.get():
            iv.disable()
            enabled.set(False)
            ui.update_action_button("disable", label = "Enable")
        else:
            iv.enable()
            enabled.set(True)
            ui.update_action_button("disable", label = "Disable")



app = App(app_ui, server)

@gadenbuie gadenbuie removed the request for review from schloerke January 8, 2025 20:09
@gadenbuie gadenbuie requested a review from cpsievert January 21, 2025 18:39
@gadenbuie gadenbuie merged commit c87dd8d into main Jan 22, 2025
@gadenbuie gadenbuie deleted the fix/8-await-custom-message branch January 22, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coroutine 'SessionProxy.send_custom_message' Was Never Awaited
2 participants