ferruzzi commented on code in PR #59066:
URL: https://github.com/apache/airflow/pull/59066#discussion_r2590628011


##########
airflow-core/src/airflow/models/taskinstance.py:
##########
@@ -304,6 +304,7 @@ def clear_task_instances(
                     dr.last_scheduling_decision = None
                     dr.start_date = None
                     dr.clear_number += 1
+                    dr.queued_at = timezone.utcnow()

Review Comment:
   Digging a bit deeper, here's what I did in main (so without this PR/change 
applied):
   
   Add the following debug statements to be the first lines of 
`airflow/airflow-core/src/airflow/models/dagrun.py::set_state`
   
   ```python
           log.warning(
               f"set_state called: _state={self._state}, new state={state}, 
condition={self._state != state}")
           if self._state != state:
               log.warning(f"Setting queued_at for state={state}")
               if state == DagRunState.QUEUED:
                   self.queued_at = timezone.utcnow()
   ```
   
   Then clear a dag and watch the server logs for the output.  This is what I 
see
   
   ```
   set_state called: _state=failed, new state=queued, condition=True
   Setting queued_at for state=queued
   ```
   
   So the setter IS getting called, but not applied in the db.  I'm still 
learning SQLAlchemy stuff, so I pointed an LLM at it ((so take this for what 
it's worth... which isn't necessarily much...))  It says this is an SQLAlchemy 
thing because we are combining the setter with direct manipulation of the ORM 
which maybe sounds plausible.
   
   LLM analysis (again, take it as such):
   ```
   Here's what's happening:
   
   1. Line 282: `dr.state = dag_run_state` → Calls `set_state()` → Sets 
`queued_at` ✓
   2. Lines 283-309: Explicit field assignments (`dr.start_date = ...`, etc.)
   3. Problem: SQLAlchemy session/ORM doesn't properly track the 
property-setter change as "dirty"
    when followed by explicit field assignments
   
   The root cause: SQLAlchemy ORM behavior - when you use a property setter 
followed by direct 
   field assignments in the same transaction, the setter's changes may not be 
marked as 
   dirty/changed for persistence.
   ```



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