From 66c315b98879ce06a01e1266bfea0e8195e21cd8 Mon Sep 17 00:00:00 2001 From: JeanCoiron Date: Sun, 15 Jun 2025 14:04:51 +0200 Subject: [PATCH 1/2] Update exampledag.py using aiflow.sdk using airflow.sdk instead of airflow.decorator to import dag and task using RuntimeTaskInstanceProtocol instead of context --- airflow/include/airflow3/exampledag.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/airflow/include/airflow3/exampledag.py b/airflow/include/airflow3/exampledag.py index 3aa21d2d7..d9fe81f60 100644 --- a/airflow/include/airflow3/exampledag.py +++ b/airflow/include/airflow3/exampledag.py @@ -21,7 +21,8 @@ """ from airflow.sdk.definitions.asset import Asset -from airflow.decorators import dag, task +from airflow.sdk.types import RuntimeTaskInstanceProtocol +from airflow.sdk import dag, task from pendulum import datetime import requests @@ -41,7 +42,7 @@ def example_astronauts(): # Define a dataset outlet for the task. This can be used to schedule downstream DAGs when this task has run. outlets=[Asset("current_astronauts")] ) # Define that this task updates the `current_astronauts` Dataset - def get_astronauts(**context) -> list[dict]: + def get_astronauts(ti: RuntimeTaskInstanceProtocol) -> list[dict]: """ This task uses the requests library to retrieve a list of Astronauts currently in space. The results are pushed to XCom with a specific key @@ -71,7 +72,7 @@ def get_astronauts(**context) -> list[dict]: {"craft": "Tiangong", "name": "Ye Guangfu"}, ] - context["ti"].xcom_push( + ti.xcom_push( key="number_of_people_in_space", value=number_of_people_in_space ) return list_of_people_in_space From 2c484bbb6e6ff32de2a34b0f1b895b9c717c6ed4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Jun 2025 12:08:36 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- airflow/include/airflow3/exampledag.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/airflow/include/airflow3/exampledag.py b/airflow/include/airflow3/exampledag.py index d9fe81f60..d3c153373 100644 --- a/airflow/include/airflow3/exampledag.py +++ b/airflow/include/airflow3/exampledag.py @@ -72,9 +72,7 @@ def get_astronauts(ti: RuntimeTaskInstanceProtocol) -> list[dict]: {"craft": "Tiangong", "name": "Ye Guangfu"}, ] - ti.xcom_push( - key="number_of_people_in_space", value=number_of_people_in_space - ) + ti.xcom_push(key="number_of_people_in_space", value=number_of_people_in_space) return list_of_people_in_space @task