What to do when Airflow BashOperator fails with TemplateNotFound error
Airflow has an annoying error that causes a failure when we try to use the BashOperator like this:
1
2
3
4
operator = BashOperator(
task_id='operator_id',
bash_command='some_bash_script.sh',
dag=dag)
What is wrong? For some reason, it tries to apply the template variables to the “bash_command” parameter even if we don’t use them. Consequently, the template loader fails with the TemplateNotFound error because it cannot find any template variables in the given string.
Of course, in this case, it is the correct behavior because we don’t use any template variables. Unfortunately, it is not the behavior we want.
To make Airflow ignore the missing template and just use the given string as the file name (as it should do anyway), we have to trick the template parsing code by adding a single space at the end of the parameter:
1
2
3
4
operator = BashOperator(
task_id='operator_id',
bash_command='some_bash_script.sh ',
dag=dag)
Did you enjoy reading this article?
Would you like to learn more about leveraging AI to drive growth and innovation, software craft in data engineering, and MLOps?
Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!
You may also like
- Doing data quality checks using the SQLCheckOperator
- Anomaly detection in Airflow DAG using Prophet library
- How to set a different retry delay for every task in an Airflow DAG
- How to trigger an Airflow DAG from another DAG
- How to retrieve the statuses of the recent DAG executions from Airflow database

Bartosz Mikulski
- MLOps engineer by day
- AI and data engineering consultant by night
- Python and data engineering trainer
- Conference speaker
- Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
- Twitter: @mikulskibartosz
- Mastodon: @mikulskibartosz@mathstodon.xyz