What parameters can be passed to Airflow @task decorator?

Question:

I am using Airflow 2.4.0.

from airflow.decorators import task
from airflow import DAG

with DAG(
        "hello_world",
        start_date=datetime(2022, 1, 1),
        schedule_interval="@daily",
        catchup=False,
) as dag:
    @task()
    def get_name():
        return {
            'first_name': 'Hongbo',
            'last_name': 'Miao',
        }

    get_name()

Currently I am using @task(). Based on the document https://airflow.apache.org/docs/apache-airflow/stable/tutorial/taskflow.html, it seems I can also use

@task(multiple_outputs=True)
@task(retries=3)
@task(task_id="get_name")

However, it does not include the explanation.

When I use multiple_outputs=True or multiple_outputs=False, or not it, the task still runs well. So I am wondering what is the purposes of it.

Is there a document listing all parameters for @task decorator that I can use and their actual functions? Thanks!

Asked By: Hongbo Miao

||

Answers:

Save the multiple_outputs optional argument declared in the task_decoratory_factory, every other option passed is forwarded to the underlying Airflow Operator.

When using task decorator as-is like

@task
def fn(): pass

the default operator is the PythonOperator.

You can explore the mandatory/optional parameters for the Airflow Operator encapsulated by the decorator to have a better idea of the signature for the specific task.

Answered By: Oluwafemi Sule
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.