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


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -465,33 +465,39 @@ def get_grid_ti_summaries_stream(
 
     The serialized Dag structure is loaded once and reused for all runs that
     share the same ``dag_version_id``, avoiding repeated deserialization.
+
+    Each iteration opens and closes its own DB session so the connection is

Review Comment:
   Nit: This shouldn't be in the doc comment, just a normal comment



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -465,33 +465,39 @@ def get_grid_ti_summaries_stream(
 
     The serialized Dag structure is loaded once and reused for all runs that
     share the same ``dag_version_id``, avoiding repeated deserialization.
+
+    Each iteration opens and closes its own DB session so the connection is
+    released between yields.  This prevents a slow client from holding a
+    database connection open for the entire stream duration.
+    See https://github.com/apache/airflow/issues/65010.
     """
 
     def _generate() -> Generator[str, None, None]:
         serdag_cache: dict[Any, SerializedDagModel | None] = {}
         for run_id in run_ids or []:
-            tis = session.execute(
-                select(
-                    TaskInstance.task_id,
-                    TaskInstance.state,
-                    TaskInstance.dag_version_id,
-                    TaskInstance.start_date,
-                    TaskInstance.end_date,
-                    DagVersion.version_number,
+            with create_session(scoped=False) as session:
+                tis = session.execute(
+                    select(
+                        TaskInstance.task_id,
+                        TaskInstance.state,
+                        TaskInstance.dag_version_id,
+                        TaskInstance.start_date,
+                        TaskInstance.end_date,
+                        DagVersion.version_number,
+                    )
+                    .outerjoin(DagVersion, TaskInstance.dag_version_id == 
DagVersion.id)
+                    .where(TaskInstance.dag_id == dag_id)
+                    .where(TaskInstance.run_id == run_id)
+                    .order_by(TaskInstance.task_id)
+                    .execution_options(yield_per=1000)
+                )
+                summary = _build_ti_summaries(
+                    dag_id,
+                    run_id,
+                    tis,
+                    session,
+                    serdag_cache=serdag_cache,
                 )
-                .outerjoin(DagVersion, TaskInstance.dag_version_id == 
DagVersion.id)
-                .where(TaskInstance.dag_id == dag_id)
-                .where(TaskInstance.run_id == run_id)
-                .order_by(TaskInstance.task_id)
-                .execution_options(yield_per=1000)

Review Comment:
   We likely still want to keep this option?



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