This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new e1f51edc9cc Accept `start_date` as string in `default_args` when
start_date is defined in dag constructor. (#55135)
e1f51edc9cc is described below
commit e1f51edc9ccf82d4ef379353d285c411ad263f3b
Author: Karthikeyan Singaravelan <[email protected]>
AuthorDate: Tue Sep 2 03:22:42 2025 +0530
Accept `start_date` as string in `default_args` when start_date is defined
in dag constructor. (#55135)
---
task-sdk/src/airflow/sdk/definitions/dag.py | 4 +++-
task-sdk/tests/task_sdk/definitions/test_dag.py | 5 +++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/task-sdk/src/airflow/sdk/definitions/dag.py
b/task-sdk/src/airflow/sdk/definitions/dag.py
index 23c0138a4b9..7e2bd5f73d6 100644
--- a/task-sdk/src/airflow/sdk/definitions/dag.py
+++ b/task-sdk/src/airflow/sdk/definitions/dag.py
@@ -458,7 +458,9 @@ class DAG:
def __attrs_post_init__(self):
from airflow.sdk import timezone
- # Apply the timezone we settled on to end_date if it wasn't supplied
+ # Apply the timezone we settled on to start_date, end_date if it
wasn't supplied
+ if isinstance(_start_date := self.default_args.get("start_date"), str):
+ self.default_args["start_date"] = timezone.parse(_start_date,
timezone=self.timezone)
if isinstance(_end_date := self.default_args.get("end_date"), str):
self.default_args["end_date"] = timezone.parse(_end_date,
timezone=self.timezone)
diff --git a/task-sdk/tests/task_sdk/definitions/test_dag.py
b/task-sdk/tests/task_sdk/definitions/test_dag.py
index 14fa059d3d1..ed8db6b0aac 100644
--- a/task-sdk/tests/task_sdk/definitions/test_dag.py
+++ b/task-sdk/tests/task_sdk/definitions/test_dag.py
@@ -72,6 +72,11 @@ class TestDag:
def test_dag_naive_start_date_string(self):
DAG("DAG", schedule=None, default_args={"start_date": "2019-06-01"})
+ def test_dag_naive_start_date_constructor_default_args_string(self):
+ dag = DAG("DAG", start_date=DEFAULT_DATE, schedule=None,
default_args={"start_date": "2019-06-01"})
+
+ assert dag.start_date == DEFAULT_DATE
+
def test_dag_naive_start_end_dates_strings(self):
DAG("DAG", schedule=None, default_args={"start_date": "2019-06-01",
"end_date": "2019-06-05"})