MohamedEqinov opened a new issue, #53135:
URL: https://github.com/apache/airflow/issues/53135

   ### Apache Airflow version
   
   3.0.2
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   When using Airflow 3.x with email_on_failure=True in task configuration, 
email notifications fail to send due to template rendering errors in the 
default email templates. This issue appears to be an ongoing regression in the 
new SDK architecture.
   
   **Issue Evolution:**
   
   **1. Airflow 3.0.1 - log_url Template Error:**
   
   ```
   UndefinedError: 'airflow.sdk.execution_time.task_runner.RuntimeTaskInstance 
object' has no attribute 'log_url'
   
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1268 in main
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1248 in finalize
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1076 in _send_task_error_email
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py",
 line 473 in _get_email_subject_content
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/helpers.py", 
line 244 in render_template_to_string
   File "<template>", line 22 in root
   ```
   
   **2. Airflow 3.0.3rc5 - mark_success_url Template Error**: After upgrading 
to 3.0.3rc5 expecting the template issue to be resolved, a different but 
similar error occurred:
   ```
   UndefinedError: 'airflow.sdk.execution_time.task_runner.RuntimeTaskInstance 
object' has no attribute 'mark_success_url'
   
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1302 in main
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1279 in finalize
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
 line 1110 in _send_task_error_email
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py",
 line 411 in _get_email_subject_content
   File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/helpers.py", 
line 244 in render_template_to_string
   File "<template>", line 26 in root
   ```
   
   **Root Cause:** The default email templates reference template variables 
(`{{ log_url }}, {{ mark_success_url }}`) that are not available in the new 
SDK's RuntimeTaskInstance object. While the log_url issue has been addressed 
between 3.0.1 and 3.0.3rc5, the mark_success_url template variable still causes 
the same type of rendering failure.
   
   **Impact:** Email notifications for task failures remain completely broken 
when using default email templates across multiple Airflow 3.x versions, 
preventing critical alerting functionality. 
   
   
   ### What you think should happen instead?
   
   **Expected Behavior**: When a task fails and email_on_failure=True is 
configured, Airflow should successfully send email notifications using the 
default email templates without any template rendering errors. The email 
notification system should work seamlessly regardless of whether the task is 
running under the legacy execution model or the new SDK architecture.
   
   **Specifically**:
   
   Tasks with email_on_failure=True should trigger email notifications on 
failure
   Default email templates should render successfully with all required 
template variables
   Email notifications should be sent via the configured SMTP connection
   Users should receive informative failure notification emails containing 
relevant task and execution details
   
   
   **Root Cause Analysis:**
   
   Incomplete SDK Migration: The new SDK architecture introduced 
RuntimeTaskInstance objects that have a different structure/interface compared 
to the legacy TaskInstance objects, but the default email templates were not 
fully updated to accommodate this change.
   
   Template Variable Mapping: The default email templates still reference 
template variables (log_url, mark_success_url) that were available in the 
legacy task instance model but are either missing, renamed, or structured 
differently in the new RuntimeTaskInstance object.
   
   Incremental Fix Approach: The fix appears to be incomplete - while log_url 
was addressed between 3.0.1 and 3.0.3rc5, mark_success_url still causes the 
same issue.
   
   Missing Template Context Adaptation: The email rendering system may need an 
adapter layer to bridge the gap between the new SDK objects and the existing 
template variables, or the templates need to be completely rewritten to use the 
correct attribute paths for the new object structure.
   
   **Suggested Solution:** Either update all default email templates to use 
template variables that are available in RuntimeTaskInstance, or provide a 
compatibility layer that maps the legacy template variables to their new 
equivalents in the SDK architecture.
   
   ### How to reproduce
   
   **Minimal Reproduction Case:**
   
   1. Setup Airflow 3.0.1 or 3.0.3rc5 (using Docker or any installation method)
   2. Configure SMTP connection via Airflow UI:
   - Go to Admin → Connections
   - Create a new connection with Connection Id: `smtp_default `(as referenced 
in the default config)
   - Set Connection Type: SMTP
   - Configure your SMTP server details (host, port, login, password)
   - Note: This approach uses the UI instead of modifying airflow.cfg since the 
default config references `email_conn_id = smtp_default`
   3. Create a simple DAG that will fail with email notifications enabled:
   ```
   from airflow import DAG
   from airflow.operators.bash import BashOperator
   from datetime import datetime, timedelta
   
   default_args = {
       "owner": "test",
       "email_on_failure": True,
       "email": ["[email protected]"],
       "retries": 0,  # No retries to fail immediately
   }
   
   with DAG(
       dag_id="test_email_failure",
       default_args=default_args,
       description="Test email failure notifications",
       schedule=None,  # Manual trigger only
       start_date=datetime(2024, 1, 1),
       catchup=False,
   ) as dag:
   
       # Task that will always fail
       failing_task = BashOperator(
           task_id="failing_task",
           bash_command="exit 1",  # Force failure
       )
   ```
   4. Trigger the DAG manually from the Airflow UI or CLI
   5. Observe the failure: : The task will fail as expected, but instead of 
sending an email notification, you'll see template rendering errors in the task 
logs.
   
   **Expected Result**: Email notification should be sent successfully using 
the smtp_default connection.
   
   **Actual Result:**
   
   In Airflow 3.0.1: UndefinedError: 'RuntimeTaskInstance object' has no 
attribute 'log_url'
   In Airflow 3.0.3rc5: UndefinedError: 'RuntimeTaskInstance object' has no 
attribute 'mark_success_url'
   
   
   ### Operating System
   
   NAME="Ubuntu" VERSION="20.04.6 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian 
PRETTY_NAME="Ubuntu 20.04.6 LTS" VERSION_ID="20.04" 
HOME_URL="https://www.ubuntu.com/"; SUPPORT_URL="https://help.ubuntu.com/"; 
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"; 
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy";
 VERSION_CODENAME=focal UBUNTU_CODENAME=focal
   
   ### Versions of Apache Airflow Providers
   
   <html><body>
   <!--StartFragment-->
   apache-airflow-providers-amazon | 9.9.0 | Amazon integration (including 
Amazon Web Services (AWS) https://aws.amazon.com/)
   -- | -- | --
   apache-airflow-providers-celery | 3.12.1 | Celery 
https://docs.celeryq.dev/en/stable/
   apache-airflow-providers-cncf-kubernetes | 10.6.1 | Kubernetes 
https://kubernetes.io/
   apache-airflow-providers-common-compat | 1.7.2 | Common Compatibility 
Provider - providing compatibility code for previous Airflow versions
   apache-airflow-providers-common-io | 1.6.1 | Common IO Provider
   apache-airflow-providers-common-messaging | 1.0.4 | Common Messaging Provider
   apache-airflow-providers-common-sql | 1.27.3 | Common SQL Provider 
https://en.wikipedia.org/wiki/SQL
   apache-airflow-providers-docker | 4.4.1 | Docker https://www.docker.com/
   apache-airflow-providers-elasticsearch | 6.3.1 | Elasticsearch 
https://www.elastic.co/elasticsearch
   apache-airflow-providers-fab | 2.3.0 | Flask App Builder 
https://flask-appbuilder.readthedocs.io/
   apache-airflow-providers-ftp | 3.13.1 | File Transfer Protocol (FTP) 
https://tools.ietf.org/html/rfc114
   apache-airflow-providers-git | 0.0.4 | Distributed version control system 
(GIT) https://git-scm.com/
   apache-airflow-providers-google | 16.1.0 | Google services including:    - 
Google Ads https://ads.google.com/  - Google Cloud (GCP) 
https://cloud.google.com/  - Google Firebase https://firebase.google.com/  - 
Google LevelDB https://github.com/google/leveldb/  - Google Marketing Platform 
https://marketingplatform.google.com/  - Google Workspace 
https://workspace.google.com/(formerly Google Suite)
   apache-airflow-providers-grpc | 3.8.1 | gRPC https://grpc.io/
   apache-airflow-providers-hashicorp | 4.3.1 | Hashicorp including Hashicorp 
Vault https://www.vaultproject.io/
   apache-airflow-providers-http | 5.3.2 | Hypertext Transfer Protocol (HTTP) 
https://www.w3.org/Protocols/
   apache-airflow-providers-microsoft-azure | 12.5.0 | Microsoft Azure 
https://azure.microsoft.com/
   apache-airflow-providers-mysql | 6.3.2 | MySQL https://www.mysql.com/
   apache-airflow-providers-odbc | 4.10.1 | ODBC 
https://github.com/mkleehammer/pyodbc/wiki
   apache-airflow-providers-openlineage | 2.5.0 | OpenLineage 
https://openlineage.io/
   apache-airflow-providers-postgres | 6.2.1 | PostgreSQL 
https://www.postgresql.org/
   apache-airflow-providers-redis | 4.1.1 | Redis https://redis.io/
   apache-airflow-providers-sendgrid | 4.1.2 | Sendgrid https://sendgrid.com/
   apache-airflow-providers-sftp | 5.3.2 | SSH File Transfer Protocol (SFTP) 
https://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/
   apache-airflow-providers-slack | 9.1.2 | Slack https://slack.com/services 
integration including:    - Slack API https://api.slack.com/  - Slack Incoming 
Webhook https://api.slack.com/messaging/webhooks
   apache-airflow-providers-smtp | 2.1.1 | Simple Mail Transfer Protocol (SMTP) 
https://tools.ietf.org/html/rfc5321
   apache-airflow-providers-snowflake | 6.5.0 | Snowflake 
https://www.snowflake.com/
   apache-airflow-providers-ssh | 4.1.1 | Secure Shell (SSH) 
https://tools.ietf.org/html/rfc4251
   apache-airflow-providers-standard | 1.4.0 | Airflow Standard Provider
   
   <!--EndFragment-->
   </body>
   
</html>[apache-airflow-providers-amazon](https://airflow.apache.org/docs/apache-airflow-providers-amazon/9.9.0/)
     9.9.0   Amazon integration (including Amazon Web Services (AWS) 
https://aws.amazon.com/)
   
[apache-airflow-providers-celery](https://airflow.apache.org/docs/apache-airflow-providers-celery/3.12.1/)
   3.12.1  Celery https://docs.celeryq.dev/en/stable/
   
[apache-airflow-providers-cncf-kubernetes](https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/10.6.1/)
 10.6.1  Kubernetes https://kubernetes.io/
   
[apache-airflow-providers-common-compat](https://airflow.apache.org/docs/apache-airflow-providers-common-compat/1.7.2/)
      1.7.2   Common Compatibility Provider - providing compatibility code for 
previous Airflow versions
   
[apache-airflow-providers-common-io](https://airflow.apache.org/docs/apache-airflow-providers-common-io/1.6.1/)
      1.6.1   Common IO Provider
   
[apache-airflow-providers-common-messaging](https://airflow.apache.org/docs/apache-airflow-providers-common-messaging/1.0.4/)
        1.0.4   Common Messaging Provider
   
[apache-airflow-providers-common-sql](https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.27.3/)
   1.27.3  Common SQL Provider https://en.wikipedia.org/wiki/SQL
   
[apache-airflow-providers-docker](https://airflow.apache.org/docs/apache-airflow-providers-docker/4.4.1/)
    4.4.1   Docker https://www.docker.com/
   
[apache-airflow-providers-elasticsearch](https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/6.3.1/)
      6.3.1   Elasticsearch https://www.elastic.co/elasticsearch
   
[apache-airflow-providers-fab](https://airflow.apache.org/docs/apache-airflow-providers-fab/2.3.0/)
  2.3.0   Flask App Builder https://flask-appbuilder.readthedocs.io/
   
[apache-airflow-providers-ftp](https://airflow.apache.org/docs/apache-airflow-providers-ftp/3.13.1/)
 3.13.1  File Transfer Protocol (FTP) https://tools.ietf.org/html/rfc114
   
[apache-airflow-providers-git](https://airflow.apache.org/docs/apache-airflow-providers-git/0.0.4/)
  0.0.4   Distributed version control system (GIT) https://git-scm.com/
   
[apache-airflow-providers-google](https://airflow.apache.org/docs/apache-airflow-providers-google/16.1.0/)
   16.1.0  Google services including: - Google Ads https://ads.google.com/ - 
Google Cloud (GCP) https://cloud.google.com/ - Google Firebase 
https://firebase.google.com/ - Google LevelDB 
https://github.com/google/leveldb/ - Google Marketing Platform 
https://marketingplatform.google.com/ - Google Workspace 
https://workspace.google.com/(formerly Google Suite)
   
[apache-airflow-providers-grpc](https://airflow.apache.org/docs/apache-airflow-providers-grpc/3.8.1/)
        3.8.1   gRPC https://grpc.io/
   
[apache-airflow-providers-hashicorp](https://airflow.apache.org/docs/apache-airflow-providers-hashicorp/4.3.1/)
      4.3.1   Hashicorp including Hashicorp Vault https://www.vaultproject.io/
   
[apache-airflow-providers-http](https://airflow.apache.org/docs/apache-airflow-providers-http/5.3.2/)
        5.3.2   Hypertext Transfer Protocol (HTTP) https://www.w3.org/Protocols/
   
[apache-airflow-providers-microsoft-azure](https://airflow.apache.org/docs/apache-airflow-providers-microsoft-azure/12.5.0/)
 12.5.0  Microsoft Azure https://azure.microsoft.com/
   
[apache-airflow-providers-mysql](https://airflow.apache.org/docs/apache-airflow-providers-mysql/6.3.2/)
      6.3.2   MySQL https://www.mysql.com/
   
[apache-airflow-providers-odbc](https://airflow.apache.org/docs/apache-airflow-providers-odbc/4.10.1/)
       4.10.1  ODBC https://github.com/mkleehammer/pyodbc/wiki
   
[apache-airflow-providers-openlineage](https://airflow.apache.org/docs/apache-airflow-providers-openlineage/2.5.0/)
  2.5.0   OpenLineage https://openlineage.io/
   
[apache-airflow-providers-postgres](https://airflow.apache.org/docs/apache-airflow-providers-postgres/6.2.1/)
        6.2.1   PostgreSQL https://www.postgresql.org/
   
[apache-airflow-providers-redis](https://airflow.apache.org/docs/apache-airflow-providers-redis/4.1.1/)
      4.1.1   Redis https://redis.io/
   
[apache-airflow-providers-sendgrid](https://airflow.apache.org/docs/apache-airflow-providers-sendgrid/4.1.2/)
        4.1.2   Sendgrid https://sendgrid.com/
   
[apache-airflow-providers-sftp](https://airflow.apache.org/docs/apache-airflow-providers-sftp/5.3.2/)
        5.3.2   SSH File Transfer Protocol (SFTP) 
https://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/
   
[apache-airflow-providers-slack](https://airflow.apache.org/docs/apache-airflow-providers-slack/9.1.2/)
      9.1.2   Slack https://slack.com/services integration including: - Slack 
API https://api.slack.com/ - Slack Incoming Webhook 
https://api.slack.com/messaging/webhooks
   
[apache-airflow-providers-smtp](https://airflow.apache.org/docs/apache-airflow-providers-smtp/2.1.1/)
        2.1.1   Simple Mail Transfer Protocol (SMTP) 
https://tools.ietf.org/html/rfc5321
   
[apache-airflow-providers-snowflake](https://airflow.apache.org/docs/apache-airflow-providers-snowflake/6.5.0/)
      6.5.0   Snowflake https://www.snowflake.com/
   
[apache-airflow-providers-ssh](https://airflow.apache.org/docs/apache-airflow-providers-ssh/4.1.1/)
  4.1.1   Secure Shell (SSH) https://tools.ietf.org/html/rfc4251
   
[apache-airflow-providers-standard](https://airflow.apache.org/docs/apache-airflow-providers-standard/1.4.0/)
        1.4.0   Airflow Standard Provider
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] 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]

Reply via email to