10

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?

zeyger
  • 1,320
  • 1
  • 12
  • 18

2 Answers2

25

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)
zeyger
  • 1,320
  • 1
  • 12
  • 18
0

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

Artem Vovsia
  • 1,520
  • 9
  • 15
  • Well yes, but I need to know whether the task was ended successfully or skipped when I look in the Airflow UI – zeyger Oct 17 '19 at 07:04