https://prefect.io logo
m

Michał Augoff

12/19/2022, 7:36 PM
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

Zanie

12/19/2022, 7:57 PM
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

Michał Augoff

12/19/2022, 8:08 PM
thanks, I’ll try with callables
what do you mean with the docstring?
z

Zanie

12/19/2022, 10:04 PM
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

Khuyen Tran

12/20/2022, 5:32 PM
You can use
date=Field(default_factory=get_today()
to create a dynamic date parameter. Here is the doc
m

Michał Augoff

12/21/2022, 12:52 AM
@Khuyen Tran could you please repost the link to the doc?
nevermind, I already built an example
k

Khuyen Tran

12/21/2022, 5:05 PM
I’m sorry. Here is the link in case you still need it
👍 1
r

rjz

02/10/2023, 6:09 AM
@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

Michał Augoff

02/10/2023, 2:27 PM
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)
3 Views