https://prefect.io logo
h

Hannah Amundson

08/12/2020, 4:12 PM
hi! is there a way to make a parameter default to the current datetime?
a

alex

08/12/2020, 4:14 PM
I believe
prefect.context.today
will give you the current date inside any task. If you want to make use it as a default parameter, couldn't you just use
datetime.today()
as the default?
h

Hannah Amundson

08/12/2020, 5:01 PM
@alex i tried this but it was maintaining the same date as when i registered the flow. i will look into today. thank you
it has been saving it as the string of when it as registered instead of the current date
a

alex

08/12/2020, 5:24 PM
If you want the actual datetime, I think
prefect.context.date
will work https://docs.prefect.io/api/latest/utilities/context.html
s

Skip Breidbach

08/12/2020, 9:26 PM
It has been a while, but I had the same result as @Hannah Amundson - once the flow was registered, the Parameter defaults were baked-in, which makes sense since (as far as I know) that code only runs once. If you really wanted the date to be a Parameter (and have it default to the current time but still be overrideable) I think you'd need a Task that accepted a Parameter and have it return the current date if that Parameter was
null
or something similar.
h

Hannah Amundson

08/12/2020, 9:31 PM
ok thank you @Skip Breidbach and @alex