gfelot opened a new issue #9392:
URL: https://github.com/apache/airflow/issues/9392


   **Apache Airflow version**:
   1.10.9
   
   - **Cloud provider or hardware configuration**: GCP
   - **OS** (e.g. from /etc/os-release): Debian (VM)
   
   
   **What happened**:
   
   Try to send custom email and notification to Teams with the 
`on_failure_callback`.
   Strangely I got 2 emails and 2 notifications.
   
   Something trigger twice the callback and I cannot find out what.
   
   
   
   **How to reproduce it**:
   
   Here my test DAG:
   
   ```
   from datetime import datetime
   
   from airflow import DAG
   from airflow.operators.dummy_operator import DummyOperator
   from airflow.operators.python_operator import PythonOperator
   from airflow.utils.email import send_email_smtp
   from operators.ms_teams_webhook_operator import MSTeamsWebhookOperator
   
   default_args = {
       "owner": "me",
       "depends_on_past": False,
       "start_date": datetime(2020, 6, 15),
       'email_on_failure': False
   }
   
   
   def on_failure(context):
       dag_id = context['dag_run'].dag_id
   
       task_id = context['task_instance'].task_id
   
       logs_url = 
f"https://myairflow/admin/airflow/log?dag_id={dag_id}&task_id={task_id}&execution_date={context['ts']}"
   
       teams_notification = MSTeamsWebhookOperator(
           task_id="msteams_notify_failure",
           trigger_rule="all_done",
           message=f"{dag_id} has failed on task: {task_id}",
           button_text="View log",
           button_url=logs_url,
           theme_color="FF0000",
           http_conn_id='msteams-python-webhook')
       teams_notification.execute(context)
   
       title = f"Titre {dag_id} - {task_id}"
       body = title
   
       send_email_smtp("[email protected]", title, body)
   
   
   def print_fail():
       print("Hello !")
       exit(1)
   
   
   with DAG(
           "test_email2",  # ICI
           default_args=default_args,
           schedule_interval=None
   ) as dag:
       preprocessing_started = DummyOperator(
           task_id="go_email_go"
       )
   
       python_fail = PythonOperator(
           task_id="pyhton_def",
           python_callable=print_fail,
           on_failure_callback=on_failure,
           email_on_failure=False
       )
   
   preprocessing_started >> python_fail
   
   ```
   
   Here is one try I have on Teams, I got also 2 emails in the row.
   
   
![image](https://user-images.githubusercontent.com/7879555/85064380-c7eddd00-b1ab-11ea-8720-6c34d841f83a.png)
   
   How is that possible ? I think there is a bug somewhere in the process to 
trigger the callback
   
   
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to