hey, is it possible to have dynamic default date p...
# ask-community
m
hey, is it possible to have dynamic default date parameters in deployed flows? I know date parameters are rendered in the UI with a calendar, and I know you can use Optional[date] and dynamically assign e.g. today’s date inside the flow code. But I’m wondering if there’s a way to say “today is default” and have that reflected in the UI when I create a new run (instead of having None in the UI)
1
z
Hm that’s tricky, perhaps you could use
Union[Date, Callable[[], Date]] = get_today
then if it’s a callable in your code you run it to get the date?
I’m not sure how Pydantic will render defaults that are functions
Perhaps this can also be handled with the docstring?
m
thanks, I’ll try with callables
what do you mean with the docstring?
z
Well I think we could parse docstrings on the function to get a help message for each parameter then display that in the UI?
k
You can use
date=Field(default_factory=get_today()
to create a dynamic date parameter. Here is the doc
m
@Khuyen Tran could you please repost the link to the doc?
nevermind, I already built an example
k
I’m sorry. Here is the link in case you still need it
👍 1
r
@Khuyen Tran can you give an example how a
Field
can be used for a parameter of a flow?
@Michał Augoff How were you able to achieve this?
m
you need to define a pydantic model with the arguments as attributes and then use that class as an argument to your function. At least that’s how I did it. It didn’t help for the UI portion though (I wasn’t able to display the default date in the UI)