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

   #70961 removed the `session` argument from `Trigger.clean_unused()` when it 
moved the retry loop around a new session. A caller that runs the cleanup 
inside its own transaction, for example a triggerer implementation that handles 
events and cleans up triggers in one heartbeat transaction, now fails with 
`TypeError: Trigger.clean_unused() got an unexpected keyword argument 
'session'`. #70961 is on `v3-4-test` (#74950), so this would ship in 3.4.0.
   
   This restores the keyword-only `session` argument and moves the retry up 
into `TriggerRunnerSupervisor.clean_unused()`, the one caller that owns its 
transaction. The model method still deletes at most one batch per call, and 
`Trigger.clean_unused()` without a session still runs and commits in its own 
transaction.
   
   **Why not keep the retry in the model and roll back the given session 
between attempts**, the way `retry_db_transaction` does? Because that 
transaction belongs to the caller. I checked this on Postgres by terminating 
the connection with `pg_terminate_backend` partway through the cleanup while 
the caller's transaction already held another write. The rollback-and-retry 
version reported success, the caller committed, and its earlier write was gone. 
Without a retry in the model, the error reaches whoever owns the transaction 
and nothing is lost silently. The supervisor retries on the regular scoped 
session, which recovers from the same dropped connection, so the 
`PendingRollbackError` crash from #74614 stays fixed. A Postgres-only test 
covers that path.
   
   One behaviour change for direct callers: `Trigger.clean_unused()` no longer 
retries database errors by itself. In core the supervisor was the only caller 
relying on that, and it now does the retry.
   
   The two caller-session tests fail on `main` with the `TypeError` above.
   


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