This is an automated email from the ASF dual-hosted git repository.
amoghrajesh 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 0a5c8e60130 Updated tutorial DAGs to use named parameters instead of
kwargs (#71980)
0a5c8e60130 is described below
commit 0a5c8e60130deb94595009b87013d14f3aa9290e
Author: Mukund Kulkarni <[email protected]>
AuthorDate: Sun Aug 23 11:42:41 2026 +0530
Updated tutorial DAGs to use named parameters instead of kwargs (#71980)
---
.../airflow/example_dags/example_branch_python_dop_operator_3.py | 8 ++++----
.../src/airflow/example_dags/example_params_trigger_ui.py | 6 ++----
.../src/airflow/example_dags/example_params_ui_tutorial.py | 3 +--
airflow-core/src/airflow/example_dags/tutorial_dag.py | 9 +++------
airflow-core/src/airflow/example_dags/tutorial_objectstorage.py | 4 +---
5 files changed, 11 insertions(+), 19 deletions(-)
diff --git
a/airflow-core/src/airflow/example_dags/example_branch_python_dop_operator_3.py
b/airflow-core/src/airflow/example_dags/example_branch_python_dop_operator_3.py
index 06c210676a8..d4d96f8b609 100644
---
a/airflow-core/src/airflow/example_dags/example_branch_python_dop_operator_3.py
+++
b/airflow-core/src/airflow/example_dags/example_branch_python_dop_operator_3.py
@@ -29,15 +29,15 @@ from airflow.sdk import DAG, task
@task.branch()
-def should_run(**kwargs) -> str:
+def should_run(logical_date=None) -> str:
"""
Determine which empty_task should be run based on if the logical date
minute is even or odd.
- :param dict kwargs: Context
+ :param pendulum.DateTime logical_date: The logical date for the current
execution
:return: Id of the task to run
"""
- print(f"------------- exec dttm = {kwargs['logical_date']} and minute =
{kwargs['logical_date'].minute}")
- if kwargs["logical_date"].minute % 2 == 0:
+ print(f"------------- exec dttm = {logical_date} and minute =
{logical_date.minute}")
+ if logical_date.minute % 2 == 0:
return "empty_task_1"
return "empty_task_2"
diff --git a/airflow-core/src/airflow/example_dags/example_params_trigger_ui.py
b/airflow-core/src/airflow/example_dags/example_params_trigger_ui.py
index 6d506e9f4c5..0b44f06042f 100644
--- a/airflow-core/src/airflow/example_dags/example_params_trigger_ui.py
+++ b/airflow-core/src/airflow/example_dags/example_params_trigger_ui.py
@@ -52,16 +52,14 @@ with DAG(
) as dag:
@task(task_id="get_names", task_display_name="Get names")
- def get_names(**kwargs) -> list[str]:
- params = kwargs["params"]
+ def get_names(params=None) -> list[str]:
if "names" not in params:
print("Uuups, no names given, was no UI used to trigger?")
return []
return params["names"]
@task.branch(task_id="select_languages", task_display_name="Select
languages")
- def select_languages(**kwargs) -> list[str]:
- params = kwargs["params"]
+ def select_languages(params=None) -> list[str]:
selected_languages = []
for lang in ["english", "german", "french"]:
if params[lang]:
diff --git
a/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
b/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
index 400a1f76e86..e79ea943197 100644
--- a/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
+++ b/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
@@ -316,8 +316,7 @@ with DAG(
) as dag:
# [START section_3]
@task(task_display_name="Show used parameters")
- def show_params(**kwargs) -> None:
- params = kwargs["params"]
+ def show_params(params=None) -> None:
print(f"This DAG was triggered with the following
parameters:\n\n{json.dumps(params, indent=4)}\n")
show_params()
diff --git a/airflow-core/src/airflow/example_dags/tutorial_dag.py
b/airflow-core/src/airflow/example_dags/tutorial_dag.py
index 0f891e5dd78..8068ade4da7 100644
--- a/airflow-core/src/airflow/example_dags/tutorial_dag.py
+++ b/airflow-core/src/airflow/example_dags/tutorial_dag.py
@@ -57,16 +57,14 @@ with DAG(
# [END documentation]
# [START extract_function]
- def extract(**kwargs):
- ti = kwargs["ti"]
+ def extract(ti=None):
data_string = '{"1001": 301.27, "1002": 433.21, "1003": 502.22}'
ti.xcom_push("order_data", data_string)
# [END extract_function]
# [START transform_function]
- def transform(**kwargs):
- ti = kwargs["ti"]
+ def transform(ti=None):
extract_data_string = ti.xcom_pull(task_ids="extract",
key="order_data")
order_data = json.loads(extract_data_string)
@@ -81,8 +79,7 @@ with DAG(
# [END transform_function]
# [START load_function]
- def load(**kwargs):
- ti = kwargs["ti"]
+ def load(ti=None):
total_value_string = ti.xcom_pull(task_ids="transform",
key="total_order_value")
total_order_value = json.loads(total_value_string)
diff --git a/airflow-core/src/airflow/example_dags/tutorial_objectstorage.py
b/airflow-core/src/airflow/example_dags/tutorial_objectstorage.py
index 66620122d60..da553344c04 100644
--- a/airflow-core/src/airflow/example_dags/tutorial_objectstorage.py
+++ b/airflow-core/src/airflow/example_dags/tutorial_objectstorage.py
@@ -64,7 +64,7 @@ def tutorial_objectstorage():
# [START get_air_quality_data]
@task
- def get_air_quality_data(**kwargs) -> ObjectStoragePath:
+ def get_air_quality_data(logical_date=None) -> ObjectStoragePath:
"""
#### Get Air Quality Data
This task gets air quality data from the Finnish Meteorological
Institute's
@@ -72,8 +72,6 @@ def tutorial_objectstorage():
"""
import pandas as pd
- logical_date = kwargs["logical_date"]
-
latitude = 28.6139
longitude = 77.2090