apache / apache/airflow

Notifiers when runing airflow dags locally though tests

Open
#64,649 3 comments 0 reactions 0 assignees View on GitHub
affected_version:3.1 area:core good first issue kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 9h
Merged PRs (30d)
472

Description

### Apache Airflow version

3.1.7

### What happened and how to reproduce it?

I am trying to port a Notifier to airflow 3 and ran into an issue when trying to run the code though `airflow dags test`. I reduced my dag down to
```python
import logging
from datetime import datetime

from airflow import DAG
from airflow.sdk import BaseNotifier, task

class MyNotifier(BaseNotifier):
log = logging.getLogger("MyNotifier")

def notify(self, *args) -> None:
self.log.info("Sending a really lovely message")

@task
def failing_task():
"""This task will intentionally fail."""
raise Exception("This DAG is designed to fail!")

with DAG(
dag_id="bad_dag",
start_date=datetime(2024, 1, 1),
schedule=None,
catchup=False,
tags=["test", "failing"],
on_failure_callback=MyNotifier(),
) as dag:
fail_task = failing_task()

```
And then when I run `airflow dags test bad_dag 2025-10-03T08:00:00`, the task fails as expected, but then an error is thrown

```
[2026-04-02T21:35:01.741165Z] {dagrun.py:1453} ERROR - Callback failed for bad_dag
Traceback (most recent call last):
File "/Users/jhoran/Workspace/eda_astronomer/.venv/lib/python3.12/site-packages/airflow/models/dagrun.py", line 1451, in handle_dag_callback
callback(context)
File "/Users/jhoran/Workspace/eda_astronomer/.venv/lib/python3.12/site-packages/airflow/sdk/bases/notifier.py", line 136, in __call__
self.render_template_fields(context)
File "/Users/jhoran/Workspace/eda_astronomer/.venv/lib/python3.12/site-packages/airflow/sdk/bases/notifier.py", line 92, in render_template_fields
jinja_env = self.get_template_env(dag=dag)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jhoran/Workspace/eda_astronomer/.venv/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py", line 79, in get_template_env
return dag.get_template_env(force_sandboxed=False)
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SerializedDAG' object has no attribute 'get_template_env'
```

I tried running the same dag in astronomer, there I didn't see any failure but I also didn't get any log output, so I can only assume it's working there.

### What you think should happen instead?

_No response_

### Operating System

_No response_

### Versions of Apache Airflow Providers

_No response_

### Deployment

Virtualenv installation

### 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)

Contributor guide

Open the contributing guide

Research direction

Start with the airflow dags test path and inspect sdk/bases/notifier.py, models/dagrun.py, and definitions/_internal/templater.py named in the traceback. Reproduce the failing DAG and trace how the callback receives a SerializedDAG. Done means the notifier callback runs during local DAG testing without the get_template_env error and its log output is observable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.