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

Add support for async validation functions #4024

Merged
merged 6 commits into from
Nov 22, 2024
Merged

Conversation

falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Nov 22, 2024

This PR implements feature request #4004, allowing to use async validation functions. Because the current API allows to call the validate() method synchronously, we need to await async validations in a background task and raise if a return value is expected.

Example:

async def validate(value: str):
    await asyncio.sleep(0.5)
    return 'Too short' if len(value) < 3 else None

ui.input(validation=validate)

Open tasks:

  • documentation
  • pytest

@falkoschindler falkoschindler added the enhancement New feature or request label Nov 22, 2024
@falkoschindler falkoschindler added this to the 2.6 milestone Nov 22, 2024
@falkoschindler falkoschindler marked this pull request as ready for review November 22, 2024 13:50
@falkoschindler falkoschindler requested a review from rodja November 22, 2024 13:50
@falkoschindler falkoschindler requested review from codingpaula and removed request for rodja November 22, 2024 17:13
@falkoschindler falkoschindler merged commit 1786e0a into main Nov 22, 2024
7 of 8 checks passed
@falkoschindler falkoschindler deleted the async-validation branch November 22, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants