Skip to content

Fix AttributeError when notifier renders templates with SerializedDAG#67862

Open
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:fix/notifier-serialized-dag-template-env
Open

Fix AttributeError when notifier renders templates with SerializedDAG#67862
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:fix/notifier-serialized-dag-template-env

Conversation

@GayathriSrividya
Copy link
Copy Markdown

@GayathriSrividya GayathriSrividya commented Jun 1, 2026

closes: #64649

When `airflow dags test` is used and the DAG has an `on_failure_callback` (or similar callback) that uses a `BaseNotifier`, the context passed to the callback contains a `SerializedDAG` object rather than a real `DAG`. `SerializedDAG` does not inherit from `Templater` and therefore has no `get_template_env` method.

`Templater.get_template_env` called `dag.get_template_env(force_sandboxed=False)` unconditionally whenever `dag` was truthy, raising:

```
AttributeError: 'SerializedDAG' object has no attribute 'get_template_env'
```

Fix: guard the call with `hasattr(dag, "get_template_env")` so that a dag object lacking the method (such as `SerializedDAG`) falls back to `SandboxedEnvironment` instead of crashing.


Thanks to @mscsy0104 and @Quantum0uasar for investigating this issue and outlining the fix approach in the issue thread.

@GayathriSrividya GayathriSrividya force-pushed the fix/notifier-serialized-dag-template-env branch 6 times, most recently from e63742b to 4ab3680 Compare June 2, 2026 08:05
When 'airflow dags test' triggers a DAG callback that uses a notifier,
the context's 'dag' key holds a SerializedDAG instance which does not
have a get_template_env method. BaseNotifier.render_template_fields
passes this dag to Templater.get_template_env, which unconditionally
calls dag.get_template_env() — raising AttributeError.

Guard the call with hasattr() so that a dag lacking get_template_env
(such as SerializedDAG) silently falls back to SandboxedEnvironment.

closes: apache#64649
@GayathriSrividya GayathriSrividya force-pushed the fix/notifier-serialized-dag-template-env branch from 4ab3680 to d8fdac9 Compare June 2, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifiers when runing airflow dags locally though tests

1 participant