ephraimbuddy commented on code in PR #42870:
URL: https://github.com/apache/airflow/pull/42870#discussion_r1818561433


##########
airflow/api_connexion/endpoints/task_instance_endpoint.py:
##########
@@ -425,7 +425,7 @@ def get_task_instances_batch(session: Session = 
NEW_SESSION) -> APIResponse:
     except _UnsupportedOrderBy as e:
         raise BadRequest(detail=f"Ordering with {e.order_by!r} is not 
supported")
 
-    task_instances = session.scalars(ti_query)
+    task_instances = 
session.scalars(ti_query.offset(data["page_offset"]).limit(data["page_limit"]))

Review Comment:
   ```suggestion
       ti_query = ti_query.offset(data["page_offset"]).limit(data["page_limit"])
       task_instances = session.scalars(ti_query)
   ```



##########
tests/api_connexion/endpoints/test_task_instance_endpoint.py:
##########
@@ -1032,6 +1032,56 @@ def 
test_should_raise_400_for_naive_and_bad_datetime(self, payload, expected, se
         assert response.status_code == 400
         assert expected in response.json["detail"]
 
+    def test_should_respond_200_for_pagination(self, session):
+        dag_id = "example_python_operator"
+
+        self.create_task_instances(
+            session,
+            task_instances=[
+                {"start_date": DEFAULT_DATETIME_1 + dt.timedelta(minutes=(i + 
1))} for i in range(10)
+            ],
+            dag_id=dag_id,
+        )
+
+        # First 5 items
+        response_batch1 = self.client.post(
+            "/api/v1/dags/~/dagRuns/~/taskInstances/list",
+            environ_overrides={"REMOTE_USER": "test"},
+            json={"page_limit": 5, "page_offset": 0},
+        )
+        assert response_batch1.status_code == 200, response_batch1.json
+        num_entries_batch1 = len(response_batch1.json["task_instances"])
+        assert num_entries_batch1 == 5
+        assert len(response_batch1.json["task_instances"]) == 5
+
+        # 5 items after that
+        response_batch2 = self.client.post(
+            "/api/v1/dags/~/dagRuns/~/taskInstances/list",
+            environ_overrides={"REMOTE_USER": "test"},
+            json={"page_limit": 5, "page_offset": 5},
+        )
+        assert response_batch2.status_code == 200, response_batch2.json
+        num_entries_batch2 = len(response_batch2.json["task_instances"])
+        assert num_entries_batch2 > 0
+        assert len(response_batch2.json["task_instances"]) > 0
+
+        # Match
+        ti_count = session.query(TaskInstance).filter(TaskInstance.dag_id == 
dag_id).count()

Review Comment:
   ```suggestion
           ti_count = 10
   ```



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