gingeekrishna opened a new pull request, #67572:
URL: https://github.com/apache/airflow/pull/67572

   ## Summary
   
   Fixes #66796
   
   `SELECT COUNT()` on an aggregate column always returns an integer — `None` 
from `session.scalar()` is only possible on a transient DB connectivity 
failure, not when the table is empty (which returns `0`). Using `or 0` silently 
swallows that failure and emits a zero count, which can trigger false on-call 
pages ("all DAGs disappeared!") while hiding the real problem.
   
   - Add `SerializedDagModel.get_count()` classmethod that raises 
`RuntimeError` when `session.scalar()` returns `None`, instead of masking it 
with `or 0`
   - Emit a `serialized_dag.count` gauge in `dag_processing/manager.py`'s 
`emit_metrics()` using the new method, wrapped in `try/except` so a DB error 
logs a warning but never kills the parse loop
   
   ## Changes
   
   - `airflow-core/src/airflow/models/serialized_dag.py` — add `get_count()` 
classmethod with None-guard
   - `airflow-core/src/airflow/dag_processing/manager.py` — import 
`SerializedDagModel`, add module logger, emit `serialized_dag.count` metric 
with error isolation
   
   ## Test plan
   
   - [ ] 
`tests/unit/models/test_serialized_dag.py::TestSerializedDagModel::test_get_count_returns_zero_on_empty_table`
   - [ ] 
`tests/unit/models/test_serialized_dag.py::TestSerializedDagModel::test_get_count_returns_correct_value`
   - [ ] 
`tests/unit/models/test_serialized_dag.py::TestSerializedDagModel::test_get_count_raises_on_none_result`
   - [ ] 
`tests/unit/dag_processing/test_manager.py::TestEmitMetrics::test_emit_metrics_emits_serialized_dag_count`
   - [ ] 
`tests/unit/dag_processing/test_manager.py::TestEmitMetrics::test_emit_metrics_does_not_raise_on_db_error`


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