How to skip task in Airflow operator?

Viewed 6741

Is there a way for Airflow to skip current task from the PythonOperator? For example:

def execute():
    if condition:
        skip_current_task()

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)

And also marking the task as "Skipped" in Airflow UI?

2 Answers

Figured it out! Skipping task is as easy as:

def execute():
    if condition:
        raise AirflowSkipException

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)

The easiest solution to skip a task:

def execute():
    if condition:
        return

task = PythonOperator(task_id='task', python_callable=execute, dag=some_dag)

Unfortunately, it will mark task as DONE

Related