hliu-VoleonGroup opened a new pull request, #35389:
URL: https://github.com/apache/airflow/pull/35389

   ### Intent
   This PR is trying to fix the incorrect execution date shown in SLA alerts.
   
   
   ### Context
   
   - The execution date in a triggered SLA alert is one schedule interval ahead 
of the expected one. 
   
   - In other words, the execution date of the SLA record inserted into the 
`SlaMiss` table is incorrect.
   
   - For example, if a daily task with an execution date `2023-10-23 21:00:00` 
triggers an SLA alert, the execution date in that alert will be `2023-10-24 
21:00:00` rather than `2023-10-23 21:00:00`.
   
   
   ### How to reproduce
   
   1. Create a simple DAG scheduled every 5 minutes
   
   ```
   import datetime
   from airflow.models import DAG
   from airflow.operators.bash import BashOperator
   
   DEFAULT_ARGS = {
       "owner": "test",
       "email": ["[email protected]"]
   }
   
   dag = DAG(
       dag_id="test_dag",
       schedule_interval="*/5 * * * *",
       start_date=datetime.datetime(2023, 10, 20),
       catchup=False
   )
   
   with dag:
     task = BashOperator(
         task_id="task",
         bash_command="sleep 120; dummy command",
         sla=datetime.timedelta(minutes=1))
   ```
   
   2. Enable the DAG and mark its first dagrun with execution date T as success.
   3. Its second dagrun with execution date T+5 should fail and trigger an SLA 
alert at T + 11 (T + 5 + 5 + 1).
        However, the execution date of the task in this alert will be T + 10 
instead of T + 5, which is not correct.
   4. Also, the SLA record in the `SlaMiss` table has a wrong execution date as 
well.
   
   
   ### Validation
   - The above DAG is able to trigger SLA alerts with correct execution dates.
   - Add one additional test case to cover this logic.


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