Dynamic default parameter values

Hi! Is it possible in Prefect 2 (2.7.12) to specify a dynamic default value for a parameter?
I would like to have a parameter which defaults to yesterday’s date, if not specified.
It seems to me that it is only possible by having None as a default, and then overriding it in a task somehow. Am I wrong?

I’m able to do this using by setting the parameter in in the task are you seeing some kind of error here?

from prefect import flow, task
import pendulum

@task()
def yesterday_param(yesterday=pendulum.yesterday()):
    print(yesterday)

@flow
def flow():
    yesterday_param()

if __name__ == '__main__':
    flow()

Thanks for your reply, I was overthinking it :slight_smile:

I came to this.

from prefect import flow, task
import pendulum

@task()
def state_the_date(date:pendulum.Date):
  print(f'Date param is {date=}')

@flow
def flow(date:pendulum.Date=pendulum.yesterday()):
    state_the_date(date)

if __name__ == '__main__':
    flow()

I was trying to avoid the common pitfall to pass mutable default value as a parameter, and I expected that I am going to have some kind of Parameter class as in Prefect v1. Never mind.