ColtenOuO commented on code in PR #71767:
URL: https://github.com/apache/airflow/pull/71767#discussion_r3807710607


##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -786,6 +786,19 @@ def _process_dagrun_deadline_alerts(
                         "deadline_alerts.deadline_created",
                         tags=prune_dict({"dag_id": self.dag_id, "team_name": 
team_name}),
                     )
+                else:
+                    required_dagrun_column = {
+                        SerializedReferenceModels.DagRunLogicalDateDeadline: 
"logical_date",
+                        SerializedReferenceModels.DagRunQueuedAtDeadline: 
"queued_at",
+                    }.get(type(deserialized_deadline_alert.reference))
+                    log.warning(
+                        "skipping deadline alert because the deadline 
reference evaluated to None",
+                        dag_id=self.dag_id,
+                        run_id=orm_dagrun.run_id,
+                        deadline_alert_id=deadline_alert.id,
+                        
reference_type=deserialized_deadline_alert.reference.reference_name,
+                        required_dagrun_column=required_dagrun_column,
+                    )

Review Comment:
   This `else` branch fires for every `SerializedReferenceModels.TYPES.DAGRUN` 
reference type, not just `DagRunLogicalDateDeadline`/`DagRunQueuedAtDeadline` — 
`TYPES.DAGRUN` also includes `AverageRuntimeDeadline`, `FixedDatetimeDeadline`, 
and `SerializedCustomReference`.
   
   `AverageRuntimeDeadline._evaluate_with` legitimately returns `None` while 
the Dag hasn't accumulated `min_runs` completed runs yet, and it already logs 
its own `"Not enough completed runs..."` info message for that case. With this 
change, every such call also emits a spurious WARNING here, misleadingly 
implying the reference evaluated to `None` because of a null DagRun column — 
even though `required_dagrun_column` resolves to `None` for this type (the dict 
only maps `DagRunLogicalDateDeadline`/`DagRunQueuedAtDeadline`) and this 
reference doesn't read any DagRun column at all. The same false-positive 
applies to any `SerializedCustomReference` that legitimately returns `None` for 
its own reasons.
   
   ```python
   with DAG(
       dag_id="demo",
       schedule=None,
       deadline=DeadlineAlert(
           reference=DeadlineReference.AVERAGE_RUNTIME(max_runs=10, min_runs=5),
           interval=timedelta(minutes=5),
           callback=AsyncCallback(empty_callback),
       ),
   ):
       ...
   ```
   
   Trigger it before 5 successful runs exist, and the api-server log shows both 
lines back to back:
   
   ```
   [info]    Not enough completed runs to calculate average runtime for 
dag_id=... (found 1, need 5)
   [warning] skipping deadline alert because the deadline reference evaluated 
to None
             reference_type=AverageRuntimeDeadline required_dagrun_column=None
   ```
   
   The second line is a false positive — it repeats on every trigger until the 
Dag accumulates enough run history, so it reads as an ongoing warning-level 
problem for something that's actually expected behavior.
   
   Suggest scoping the warning to only the two reference types it's documented 
for:
   
   ```python
   if type(deserialized_deadline_alert.reference) in (
       SerializedReferenceModels.DagRunLogicalDateDeadline,
       SerializedReferenceModels.DagRunQueuedAtDeadline,
   ):
       log.warning(...)
   ```
   
   so `AverageRuntimeDeadline` / `FixedDatetimeDeadline` / 
`SerializedCustomReference` returning `None` don't get this misleading warning 
attached.
   



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