0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Airflow の DAG で、start_date を明示的に設定して dag trigger したい話

Last updated at Posted at 2025-04-30

ユースケース

以下のような DAG 設定だったとする

args = {
    "owner": "shase428",
    "start_date": airflow.utils.dates.days_ago(2),
}

parent_name = "foobar_dag"

dag = DAG(
    parent_name,
    default_args=args,
    schedule_interval="0 10 * * *",

)

通常の運用では問題ないのだが、古い日付でdag triggerしたい場合、dag trigger の日付指定は、start_date より以前は指定できないため、詰む(以下のようなエラーが出る)

ValueError: The execution_date [2025-02-28T00:00:00+00:00] should be >= start_date [2025-04-28T00:00:00+00:00] from DAG's default_args

そのため、必要に応じて以下のように修正する

args = {
    "owner": "shase428,
    'start_date': datetime.datetime(2025, 2, 1),

}

parent_name = "foobar_dag"

dag = DAG(
    parent_name,
    default_args=args,
    schedule_interval="0 10 * * *",
    catchup=False,
)

ポイント

  • start_date は、airflow.utils.dates.days_ago ではなく、絶対的な日付を渡す datetime.datetime(2025, 2, 1)
  • catchup=False をつけて、勝手にbackfill実行されないようにする

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?