-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Description
Apache Airflow version
3.0.2
If "Other Airflow 2 version" selected, which one?
No response
What happened?
When running a dag via dag.test(), I receive an error when accessing the jinja variable {{ data_interval_end }} and {{ data_interval_end }}.
Ex:
UndefinedError: 'data_interval_start' is undefined
The issue is not with all jinja variables. For example, {{ task_instance_key_str }} is fine. The three vars in the below test DAG are the only 3 jinja vars I have tested.
What you think should happen instead?
The jinja var should be used with no issue. This is the behavior when triggering the below DAG in the UI.
How to reproduce
Run the below using dag.test(), only run one task at a time. I just comment out the other two. You should see the same error described in the comments above each task.
from airflow import DAG
from airflow.providers.standard.operators.python import PythonOperator
from datetime import datetime
import logging
def test_task(jinja_var: str):
logging.info(f"Printing jinja var: {jinja_var}")
with DAG(
dag_id="testdag2",
schedule="@daily",
start_date=datetime(2024, 1, 1),
catchup=False,
) as dag:
# UndefinedError: 'data_interval_start' is undefined
task1 = PythonOperator(
task_id="task_data_interval_end",
python_callable=test_task,
op_kwargs={
"jinja_var": "{{ data_interval_end }}"
}
)
# UndefinedError: 'data_interval_end' is undefined
task2 = PythonOperator(
task_id="task_data_interval_start",
python_callable=test_task,
op_kwargs={
"jinja_var": "{{ data_interval_start }}"
}
)
# Works
task3 = PythonOperator(
task_id="task_instance_key_str",
python_callable=test_task,
op_kwargs={
"jinja_var": "{{ task_instance_key_str }}"
}
)
if __name__ == "__main__":
dag.test()
Operating System
Debian GNU/Linux 12 (bookworm)
Versions of Apache Airflow Providers
apache-airflow-providers-amazon==9.8.0
apache-airflow-providers-celery==3.11.0
apache-airflow-providers-cncf-kubernetes==10.4.3
apache-airflow-providers-common-compat==1.7.0
apache-airflow-providers-common-io==1.6.0
apache-airflow-providers-common-sql==1.27.1
apache-airflow-providers-elasticsearch==6.3.0
apache-airflow-providers-http==5.3.0
apache-airflow-providers-microsoft-azure==12.4.0
apache-airflow-providers-microsoft-mssql==4.3.0
apache-airflow-providers-mysql==6.3.0
apache-airflow-providers-odbc==4.10.0
apache-airflow-providers-openlineage==2.3.0
apache-airflow-providers-postgres==6.2.0
apache-airflow-providers-samba==4.10.0
apache-airflow-providers-sftp==5.3.0
apache-airflow-providers-slack==9.1.0
apache-airflow-providers-smtp==2.1.0
apache-airflow-providers-snowflake==6.3.1
apache-airflow-providers-ssh==4.1.0
apache-airflow-providers-standard==1.2.0
Deployment
Official Apache Airflow Helm Chart
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct