karenbraganz opened a new issue, #57507: URL: https://github.com/apache/airflow/issues/57507
### Apache Airflow version 3.1.1 ### If "Other Airflow 2/3 version" selected, which one? _No response_ ### What happened? This is similar to issue [#53135](https://github.com/apache/airflow/issues/53135), which has already been fixed. However, the fix for that issue does not fix this. When email_on_failure is set to True for a task on Airflow 3, the below error message is produced when the task instance fails. ``` ERROR - Top level error: source="task" UndefinedError: 'airflow.sdk.execution_time.task_runner.RuntimeTaskInstance object' has no attribute 'mark_success_url' File "/usr/local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1302 in main File "/usr/local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1279 in finalize File "/usr/local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1110 in _send_task_error_email File "/usr/local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 411 in _get_email_subject_content File "/usr/local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 408 in render File "/usr/local/lib/python3.12/site-packages/airflow/utils/helpers.py", line 244 in render_template_to_string File "/usr/local/lib/python3.12/site-packages/airflow/utils/helpers.py", line 239 in render_template File "<template>", line 26 in root File "/usr/local/lib/python3.12/site-packages/jinja2/runtime.py", line 859 in _fail_with_undefined_error ``` This stack trace is from Airflow 3.0.3. However, this issue also exists in Airflow 3.1.1. This is happening because the RuntimeTaskInstance object that is passed as ti does not have a `mark_success_url` attribute. This attribute is used in templates for [default_html_content](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1196) and [default_html_content_err](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1204). See the code [here](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1255) where the RuntimeTaskInstance object is passed as ti when calling the _get_email_subject_content function. ### What you think should happen instead? In Airflow 3.1: The _get_email_subject_content function [receives a RuntimeTaskInstance object as the ti attribute](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1169). Since the RuntimeTaskInstance object does not have a `mark_success_url` attribute, the Mark success link should be removed from [default_html_content](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1196) and [default_html_content_err](https://github.com/apache/airflow/blob/f969e6374daa8469938169be16a28f7c073a5ce9/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1204). This will prevent the UndefinedError we are seeing. In Airflow 3.0: The _get_email_subject_content function can receive a [TaskInstance or RuntimeTaskInstance object ](https://github.com/apache/airflow/blob/e965c2e676d85ced65a485d4b2601addc2fd3e97/airflow-core/src/airflow/models/taskinstance.py#L325)as the ti attribute. A check for object type should be added to the function. The Mark Success link should only be included in templates for TaskInstance objects. This will prevent the UndefinedError we are seeing. ### How to reproduce Create a task that always fails and enable `email_on_failure` on an Airflow 3 environment. ### Operating System Debian GNU/Linux ### Versions of Apache Airflow Providers _No response_ ### 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]
