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


##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:
##########
@@ -805,9 +852,26 @@ def _change_state(
             self.log.debug("TI key not in running, not adding to event_buffer: 
%s", key)
             return
 
-        # If we don't have a TI state, look it up from the db. event_buffer 
expects the TI state
+        # If we don't have a TI state, look it up from the db. event_buffer 
expects the TI state.
+        # For callback keys there is no TaskInstance row — treat state=None as 
success directly.
         if state is None:
-            state = self._get_task_instance_state(key, session=session)
+            from airflow.models.taskinstancekey import TaskInstanceKey
+
+            if isinstance(key, TaskInstanceKey):
+                from airflow.models.taskinstance import TaskInstance
+
+                filter_for_tis = TaskInstance.filter_for_tis([key])
+                if filter_for_tis is not None:
+                    state = 
session.scalar(select(TaskInstance.state).where(filter_for_tis))
+                else:
+                    state = None
+                state = TaskInstanceState(state) if state else None
+            elif AIRFLOW_V_3_3_PLUS:
+                from airflow.utils.state import CallbackState
+
+                state = CallbackState.SUCCESS

Review Comment:
   Alright, I've been thinking about this.   It looks like this is fine how it 
is for now, but it may need some more thinking later.  Something feels off with 
the callback state flow here, but I can't place it right now.   
   
   Go ahead and resolve this when you read it.  If you do go on to do the 
callback-retry work, maybe spend some time thinking this through... it seems 
like there's a step missing here with the state updates compared to the task 
state updates.



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