pikachuev opened a new issue, #58516:
URL: https://github.com/apache/airflow/issues/58516
### Apache Airflow version
3.1.3
### If "Other Airflow 2/3 version" selected, which one?
_No response_
### What happened?
If DAG is triggered by Asset Event and uses jinja variables like `ds` or
`logical_date` it fails with error:
```python
Exception rendering Jinja template for task 'print_execution_date', field
'op_kwargs'. Template: {'ds': '{{ ds }}'}
source=airflow.sdk.definitions._internal.abstractoperator
loc=abstractoperator.py:311
UndefinedError: 'ds' is undefined
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/abstractoperator.py",
line 305 in _do_render_template_fields
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py",
line 192 in render_template
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py",
line 177 in render_template
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/abstractoperator.py",
line 266 in _render
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py",
line 133 in _render
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/context.py",
line 205 in render_template_to_string
File
"/usr/local/lib/python3.12/site-packages/airflow/sdk/definitions/context.py",
line 195 in render_template
File "<template>", line 12 in root
File "/usr/local/lib/python3.12/site-packages/jinja2/runtime.py", line 859
in _fail_with_undefined_error
```
If you trigger the same DAG manually or via cron/time schedule it will
finished without any error.
In Airflow 2.11 it worked correctly.
### What you think should happen instead?
_No response_
### How to reproduce
`dag1`:
```python
from airflow.sdk import Asset
from airflow.decorators import dag, task
from datetime import datetime
# Define the asset produced by the first DAG
sample_asset = Asset("sample_asset")
@dag(
dag_id="test_dag1",
start_date=datetime(2023, 1, 1),
catchup=False,
default_args={"owner": "airflow", "retries": 1},
)
def test_dag1():
@task(outlets=[sample_asset])
def empty_task():
print("Empty task")
empty_task()
test_dag1()
```
`dag2`:
```python
from airflow.sdk import Asset
from airflow.decorators import dag, task
from datetime import datetime
# Define the asset produced by the first DAG
sample_asset = Asset("sample_asset")
@dag(
dag_id="test_dag2",
schedule=[sample_asset], # Schedule based on the asset event from the
first DAG
start_date=datetime(2023, 1, 1),
catchup=False,
default_args={"owner": "airflow", "retries": 1},
)
def test_dag2():
"""
DAG that waits for the asset event from the first DAG and prints the
execution date.
"""
@task
def print_execution_date(ds: str):
print(f"The execution date of this DAG run is: {ds}")
print_execution_date(ds='{{ ds }}')
test_dag2()
```
If you trigger dag2 directly it works, if you trigger dag1 dag2 will fail.
### Operating System
Astro runtime
### Versions of Apache Airflow Providers
apache-airflow-providers-microsoft-azure==12.8.1
apache-airflow-providers-snowflake==6.6.1
apache-airflow-providers-dbt-cloud==4.5.0
azure-identity==1.25.1
msgraph-sdk==1.48.0
pydantic-settings==2.12.0
### Deployment
Astronomer
### 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
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]