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

   ### Description
   
   `DagRunContext._sanitize_consumed_asset_events` only recovered from 
`DetachedInstanceError` while loading `consumed_asset_events`. When the 
DagRun's session transaction was invalidated by a prior database error, the 
lazy load raises `PendingRollbackError` (or `InvalidRequestError` once the 
session is closed) instead. That escaped the validator, aborted 
`DagRun.update_state() -> produce_dag_callback()`, and the scheduler's generic 
error handling around `_schedule_dag_run()` swallowed the exception — so the 
Dag-level `on_failure_callback` was silently dropped and only the `callback is 
empty` debug line hinted at it. This is the failure mode behind #63374.
   
   The recovery now:
   
   - catches `SQLAlchemyError` (not just `DetachedInstanceError`) around the 
relationship access;
   - reads the primary key through the instance identity, since attribute 
access on the broken instance would re-raise on the same failed session;
   - reloads the DagRun with eager-loaded relationships on a fresh session and 
hands the freshly loaded instance to validation (the broken instance's expired 
attributes would keep the datamodel conversion failing);
   - degrades to empty `consumed_asset_events` if the row was deleted in the 
meantime;
   - `_send_dag_callbacks_to_processor()` now logs which Dag callback is sent, 
so the sent and the missing case are distinguishable in DEBUG output.
   
   The approach follows the review guidance from #69991 ("the fix belongs in 
the callback-production path used by `DagRun.update_state()`") and builds on 
the root-cause analysis from the earlier #63692 and the withdrawn #76629 — 
credit to @Sathvik-Chowdary-Veerapaneni and @Abolfazlrwm for those.
   
   closes #63374
   
   ### Are these changes user-facing?
   
   Yes, bug fix: DAG-level `on_failure_callback` / `on_success_callback` 
requests are no longer silently dropped when the scheduler session is in a 
failed state.
   
   ### How was this patch tested?
   
   - two new regression tests in 
`airflow-core/tests/unit/callbacks/test_callback_requests.py`: one poisons an 
independent session with a failed flush (`PendingRollbackError`) and asserts 
the context is still built from a fresh reload; one deletes the row behind a 
detached instance's back and asserts graceful degradation;
   - the existing `Detached`/`attached` recovery tests still pass;
   - `tests/unit/models/test_dagrun.py -k callback` (21 tests) passes;
   - ruff check + format clean.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — TeleAgent
   
   Generated-by: TeleAgent following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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