Hi, Just arrived. I have registered a flow and hav...
# prefect-community
p
Hi, Just arrived. I have registered a flow and have added the CronSchedule. It gets scheduled on the right time but it is picking up the wrong date
Copy code
flow.schedule = CronSchedule("49 21 * * 1-5",start_date=pendulum.datetime(2022, 1, 1, tz="Asia/Kolkata"),)

flow.register(
      project_name=project_name,
      idempotency_key=flow.serialized_hash(),
      labels=["test"],
    )
What could be the reason for this?
k
What date is it picking up for you?
p
So I had registered the flow yesterday and yesterday it worked fine
But today it is picking up the yesterday's date only
k
Is that related to your schedule or do you have a date Parameter in your flow?
p
Copy code
# -- Write you flows here
  with Flow(workflow_name) as flow:
    today_date = datetime.datetime.now(pytz.timezone('Asia/Kolkata')).strftime("%Y%m%d")
    date = Parameter("date", default=today_date
k
Yeah exactly. That date is fixed during the registration time. You need to make it a task so that it’s evaluated during runtime.
Copy code
@task
def get_date(val):
    if val == None:
        return datetime.datetime.now(pytz.timezone('Asia/Kolkata')).strftime("%Y%m%d")

with Flow(...) as flow:
    the_date = Parameter("today", default=None)
    the_date = get_date(the_date)
p
Thanks Kevin - let me try this and get back
k
The issue is the default is evaluated immediately during registration