bbovenzi commented on code in PR #75725:
URL: https://github.com/apache/airflow/pull/75725#discussion_r4471697102


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -608,15 +619,41 @@ def _generate() -> Generator[str, None, None]:
                     .order_by(TaskInstance.task_id)
                     .execution_options(yield_per=1000)
                 )
+                structure_version_id = None
+                if has_date_filter:
+                    structure_version_id = session.scalar(
+                        select(TaskInstance.dag_version_id)
+                        .join(DagVersion, TaskInstance.dag_version_id == 
DagVersion.id)
+                        .where(TaskInstance.dag_id == dag_id, 
TaskInstance.run_id == run_id)
+                        .order_by(DagVersion.version_number.desc())
+                        .limit(1)
+                    )
+                    query = query.where(
+                        or_(
+                            TaskInstance.state != 
TaskInstanceState.UP_FOR_RETRY, TaskInstance.state.is_(None)
+                        )
+                    ).execution_options(include_all_attempts=True)
+                query = start_date_range.to_orm(query)
+                query = end_date_range.to_orm(query)
+                tis = session.execute(query)
                 summary = _build_ti_summaries(
                     dag_id,
                     run_id,
                     tis,
                     session,
                     dag_bag=dag_bag,
+                    structure_version_id=structure_version_id,
                 )
-            if summary is None:
-                continue
+                if summary is None:

Review Comment:
   this is the same “filtered, but the run exists → return an empty result 
instead of nothing” check as filtered_existing_run in gantt.py
   
   Let's make a shared util



##########
files/gantt-real-ui-after.png:
##########


Review Comment:
   Delete this file



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -608,15 +619,41 @@ def _generate() -> Generator[str, None, None]:
                     .order_by(TaskInstance.task_id)
                     .execution_options(yield_per=1000)
                 )
+                structure_version_id = None
+                if has_date_filter:
+                    structure_version_id = session.scalar(
+                        select(TaskInstance.dag_version_id)
+                        .join(DagVersion, TaskInstance.dag_version_id == 
DagVersion.id)
+                        .where(TaskInstance.dag_id == dag_id, 
TaskInstance.run_id == run_id)
+                        .order_by(DagVersion.version_number.desc())
+                        .limit(1)
+                    )
+                    query = query.where(
+                        or_(
+                            TaskInstance.state != 
TaskInstanceState.UP_FOR_RETRY, TaskInstance.state.is_(None)
+                        )
+                    ).execution_options(include_all_attempts=True)

Review Comment:
   `include_all_attempts` counts each archived attempt as a child, so when 
filtered child_states and the overall state can change.



##########
files/gantt-real-ui-before.png:
##########


Review Comment:
   Delete this file



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -608,15 +619,41 @@ def _generate() -> Generator[str, None, None]:
                     .order_by(TaskInstance.task_id)
                     .execution_options(yield_per=1000)
                 )
+                structure_version_id = None
+                if has_date_filter:

Review Comment:
   The structure shouldn’t change because a filter was added. Unfiltered, we 
build the tree from first.dag_version_id. Filtered, we use the newest live 
version. On a run whose TIs span Dag versions, adding a date pill can regroup 
tasks under different group bars.
   
   Can we pick the version the same way in both paths (from live TIs only, 
ignoring archived attempts)? 



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