Gautam-Bharadwaj commented on PR #63663:
URL: https://github.com/apache/airflow/pull/63663#issuecomment-4066539377

   @potiuk The primary goal here is to make these utility functions atomic and 
transaction-safe when called within a larger session (like `initdb` or 
`create_default_connections`). 
   
   Currently, `merge_conn` is called in a loop inside 
`create_default_connections`. If `merge_conn` contains a `commit()`, it forces 
a commit on every single iteration. This is not only slow but also prevents 
`create_default_connections` from being an atomic operation—if it fails 
halfway, the first half remains committed. By moving to `flush()`, we allow the 
outer `@provide_session` (in `create_default_connections`) to manage the single 
final commit.
   
   Importantly, this change is largely backwards compatible for standalone 
callers. Because these functions are decorated with `@provide_session`, if they 
are called without an external session, the wrapper will create a new session, 
call the function, and then **commit it** upon exit. So `merge_conn(conn)` will 
still result in a persistent change in the DB immediately.
   
   The only difference is when a `session` is passed from outside—and in that 
case, the caller typically expects to control the transaction boundary. Does 
this make sense, or do you see a specific case where a nested commit is 
preferred?


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