ashb commented on code in PR #45813:
URL: https://github.com/apache/airflow/pull/45813#discussion_r1922854466


##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -161,6 +162,15 @@ def set_rtif(self, id: uuid.UUID, body: dict[str, str]) -> 
dict[str, bool]:
         # decouple from the server response string
         return {"ok": True}
 
+    def get_previous_successful_dagrun(self, id: uuid.UUID) -> 
PrevSuccessfulDagRunResponse:
+        """
+        Get the previous successful dag run for a given task instance.
+
+        The data from it is used to get values for Task Context.
+        """
+        resp = 
self.client.get(f"task-instances/{id}/previous_successful_dagrun")

Review Comment:
   Consistency of URL please 
   ```suggestion
           resp = 
self.client.get(f"task-instances/{id}/previous-successful-dagrun")
   ```



##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -393,6 +394,42 @@ def ti_put_rtif(
     return {"message": "Rendered task instance fields successfully set"}
 
 
[email protected](
+    "/{task_instance_id}/previous_successful_dagrun",
+    status_code=status.HTTP_200_OK,
+    responses={
+        status.HTTP_404_NOT_FOUND: {"description": "Task Instance or Dag Run 
not found"},
+    },
+)
+def get_previous_successful_dagrun(
+    task_instance_id: UUID, session: SessionDep
+) -> PrevSuccessfulDagRunResponse:
+    """
+    Get the previous successful DagRun for a TaskInstance.
+
+    The data from this endpoint is used to get values for Task Context.
+    """
+    ti_id_str = str(task_instance_id)
+    task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+    if not task_instance:
+        return PrevSuccessfulDagRunResponse()
+
+    dag_run = session.scalar(
+        select(DR)
+        .where(
+            DR.dag_id == task_instance.dag_id,
+            DR.logical_date < task_instance.logical_date,

Review Comment:
   I think @uranusjr is about to break this. Quick, lets merge it while it 
still works >_>



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