```def main(date: DateModel = None) -> None:```...
# best-practices
s
Copy code
def main(date: DateModel = None) -> None:
How can I use the current date for flow_run_name? Unless doing data for another day, I don't call the flow with any arguments.
n
hi @Stefan - if you're using prefect >= 2.7.12, you can use the new templating feature to name your flow runs like
Copy code
from datetime import datetime
from prefect import flow, task

@task(task_run_name="{name}")
def my_task(name):
  print(f"hi {name}")

@flow(flow_run_name="{name}-on-{date:%m-%d-%Y}")
def my_flow(name: str, date: datetime):
  return my_task(name)

my_flow("Nate", datetime.now())
s
But since I schedule flow runs in the UI I wouldn't have that last line calling "my_flow"
n
ahh yes, sorry i missed that bit from your first message. im not sure theres a direct way to give custom names to flow runs created by the scheduler, but whats your use case? perhaps we can achieve it slightly differently
s
Hi again Nate! So I have a lot of scripts that run on the daily. Before prefect, we'd call them using argparse if we had to perform the job for previous dates. So for a day-to-day basis, I will not call my flow with any parameter, as it will do the job for -todays date-. Maybe there could be a config option to generate a flow run name from todays date in a specified string?
n
hi @Stefan
Maybe there could be a config option to generate a flow run name from todays date in a specified string?
that sounds reasonable to me, let me raise it to the team
s
Thanks @Nate! I did an experiment: From the looks of it, the flow run is generated with "vagabond-impala" but quickly changes to my specified one with a dynamic date. This is my def:
Copy code
def main(year_month: str = (datetime.datetime.today() - relativedelta(months=1)).strftime('%Y%m')):
and so in the decorator:
Copy code
flow_run_name="azure2aisyrisk for {year_month}",
Update @Nate. This only works when calling a Flow from the command line. The parameters is successfully parsed as input to the flow_run_name. When calling from the UI, I get a KeyError as it is not defined.