dabla commented on code in PR #77550:
URL: https://github.com/apache/airflow/pull/77550#discussion_r4686433367


##########
airflow-core/src/airflow/models/taskinstance.py:
##########
@@ -1815,6 +1859,7 @@ def get_last_try_numbers(
 
     def prepare_db_for_next_try(self, session: Session) -> TaskInstance:
         """Archive this UUID and return its successor in the caller's 
transaction."""
+        # _reset_orphaned_attempts writes the same rows in bulk; change both.

Review Comment:
   **[warning]** Two writers of the same rows, kept in step by a "change both" 
comment.
   
   `_reset_orphaned_attempts` repeats three things that `archive()` and 
`prepare_db_for_next_try()` already do: lock the current rows and refuse an 
attempt that left the working set, write the archived columns, and build the 
successor row plus its carried note. The two helpers this PR extracts 
(`_get_archived_changes`, `_get_successor_overrides`) share the decisions, and 
the column-by-column test catches a drift in what is written today, but a 
column or child row added to one path later still has to be remembered in the 
other, and the comment is the only thing that says so.
   
   Would it work to have one writer and make the single attempt its one-element 
case? The bulk method already takes the per-row inputs from the objects; with 
the successor's `state` and `retry_at` passed per attempt (today fixed to 
`None`), `prepare_db_for_next_try` could call it with `[self]` and load the 
successor it returns, and the `up_for_retry` detour inside the bulk method 
would go away with it. The cost is that the single path then archives through a 
Core `UPDATE` followed by `set_committed_value`, as the bulk path does now, 
where it flushes ORM changes today, so every caller of 
`prepare_db_for_next_try` would need the same before/after check your new test 
does for the orphan path.
   
   If that is more than this PR should carry, I am fine with it as a follow-up, 
but I would rather see it tracked than left to the comment.



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