I use BashOperator to execute a python file in Airflow, how to import other self-defined function?

Viewed 265

I use BashOperator to execute a python file called app.py in Airflow. I wrote another python script called to_es.py. There is a function called "df_to_es()" in it.

The app.py should call df_to_es() by from utils.to_es import df_to_es, but the Airflow throws an error in red words: 'there is no module called "def_to_es"'.

1 Answers

Finally I come to answer my own question.
Even though Airflow may indicate that there is a DAG import error, but if you use BashOperator to execute your Python script, you import your own python functions, classes and modules in that script, they work smoothly if you don't have some other errors. Just double check if you are using correct Airflow DAG directory.
So just ignore that DAG import error if you are in my situation. This is something that Airflow develop team need to improve. Something like unit test.

Related