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
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
)
For anyone else receiving this, the error is due to the task and the python_callable function having the same name.
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
)
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
.
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
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
)
For anyone else receiving this, the error is due to the task and the python_callable function having the same name.
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
)
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
.