AirFlowException – Python_Callable must be callable

Question:

I made a small change to an existing workflow, and it has broken airflow. Here is the code:

dag_name = platform + "_" + report['table']

dag = DAG(
    dag_name,
    catchup=True,
    default_args=default_args,
    schedule_interval=report['schedule']
)

with dag:

    trigger_report = PythonOperator(
        task_id=dag.dag_id + '_trigger_report',
        python_callable=trigger_report,
        provide_context=True,
        op_kwargs={
            'report_name': report['report'],
            'amazonmws_conn_id': default_args['amazonmws_conn_id']
        },
        dag=dag
    )

Here is the error I’m receiving:

airflow.exceptions.AirflowException: python_callable param must be callable

Asked By: Ashley O

||

Answers:

seems like you are passing trigger_report itself as the python_callable.

Is this intentional? does it already have a value?
(probably, otherwise you would’ve gotten a NameError: name 'trigger_report' is not defined)

Answered By: Adam.Er8

For anyone else receiving this, the error is due to the task and the python_callable function having the same name.

Answered By: Chris K

The error is obvious, you are putting a PythonOperator inside a variable and calling that variable as a python function inside a PythonOperator!!!!

1- python callable must be a function and not a variable.

2- you shouldnt and cant call same thing inside a function.

3- in your case trigger_report is a task and something related to airflow and not python basic things.

Update for similar errors:

If you cared to follow the above but the problem was insisting.
You must make a non-callable, callable.

use functools

heres an example:

import functools

def your_func(value1):
    return ""

trigger_report = PythonOperator(
    task_id="aaaa",
    python_callable=functools.partial(your_func, value1=1),
    provide_context=True,
    dag=dag
)
Answered By: Aramis NSR

This error also happens if the function name you pass to python_callable has brackets. So, if your function is abc(), you should pass python_callable=abc.

Answered By: Satyaki Mallick