Hi Everyone, How can I pass an the current date (m...
# ask-community
r
Hi Everyone, How can I pass an the current date (must update daily) to a deployment script parameter? This particular deployment needs to automatically update the "calendar_date" parameter to the latest date. I tried using the "from datetime import date" and the creating an internal variable that returns the latest date based the function date.today() but the argument does not change once the script is deployed. I also tried to use a helper function to return the latest date, but again the parameter does not change. How can I solve this problem?
from helper_functions import calc_date
from prefect.deployments import Deployment
from prefect.server.schemas.schedules import CronSchedule
from datetime import date, timedelta
_yesterday_str = calc_date.fn()
deploy_flow = Deployment.build_from_flow(
flow=my_test_deployment,
name="Test",
storage=,
path="",
entrypoint=f"xxx/yyy",
schedule=CronSchedule(cron="0 10 * * *", timezone="America/New_York"),
work_queue_name="Hawk1",
tags=["ETL", 'JSON'],
description="This Prefect flow performs ingests, loads, and Transforms data for ...",
parameters=dict(calendar_date=f'{_yesterday_str}'
)
)
if __name__ == "__main__":
deploy_flow.apply()
n
hi @Robert Esteves - thered be a couple different ways you can solve this easiest
Copy code
@flow
def test_flow(..., lookback_days: int = 1):
  _yesterday_str = datetime.now() - timedelta(days=lookback_days)

  ...
using pydantic to avoid this logic being in your flow
Copy code
from datetime import datetime, timedelta

from prefect import flow
from pydantic import BaseModel, computed_field # comes with prefect

class DateInfo(BaseModel):
   lookback_days: int = 1

   @computed_field
   @property
   def yesterday(self) -> datetime:
      return datetime.now() - timedelta(days=self.lookback_days)

@flow
def test_flow(date_info: DateInfo = DateInfo()):
  assert date_info.yesterday == "the actual date string you want"
r
@Nate Thanks for your assistance and support. We implemented a solution similar to what you are showing in your code.
n
catjam