kaxil commented on code in PR #68423: URL: https://github.com/apache/airflow/pull/68423#discussion_r3406844088
########## airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py: ########## @@ -79,6 +80,23 @@ DEFAULT_RENDERED_MAP_INDEX = "test rendered map index" [email protected] +def _capture_task_instance_selects(session): + statements = [] + + def collect_selects(conn, cursor, statement, parameters, context, executemany): + normalized = " ".join(statement.lower().split()) + if normalized.startswith("select") and " from task_instance" in normalized: Review Comment: Minor: `" from task_instance"` also matches `task_instance_history` / `task_instance_note`, so the count would pick those up if these endpoints ever gain such queries. `re.search(r"\bfrom task_instance\b", normalized)` would pin it to exactly the `task_instance` table. ########## airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py: ########## @@ -1163,9 +1156,13 @@ def get_task_instance_states( run_id_task_state_map: dict[str, dict[str, Any]] = defaultdict(dict) query = select(TI).where(TI.dag_id == dag_id) + selected_task_ids = list(task_ids or []) - if task_ids: - query = query.where(TI.task_id.in_(task_ids)) + if task_group_id: + selected_task_ids.extend(_get_group_task_ids(dag_id, task_group_id, session, dag_bag)) + + if selected_task_ids or task_group_id: Review Comment: The `or task_group_id` is load-bearing: when the group resolves to zero tasks, the filter still has to apply (empty `IN`, matches nothing) instead of falling away and returning every TI in the dag. Worth a short comment so nobody simplifies this to `if selected_task_ids:` later? -- 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]
