hi! is there a way to make a parameter default to ...
# ask-community
h
hi! is there a way to make a parameter default to the current datetime?
a
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
@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
If you want the actual datetime, I think
prefect.context.date
will work https://docs.prefect.io/api/latest/utilities/context.html
s
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
ok thank you @Skip Breidbach and @alex