You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "gopidesupavan (via GitHub)" <gi...@apache.org> on 2025/04/26 11:45:09 UTC

[PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

gopidesupavan opened a new pull request, #49818:
URL: https://github.com/apache/airflow/pull/49818

   Adding mapping index option to GetTICount and GetTaskStates.
   
   The default option is None, because if the user not input any task_ids/task_group_id, we would want to fetch all the tasks that satsfies other condition(dag_id, run_ids).
   
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2066843471


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   We don't need it



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063072433


##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -231,12 +232,16 @@ def get_count(
         # Remove None values from params
         params = {k: v for k, v in params.items() if v is not None}
 
+        if map_index is not None and map_index >= 0:
+            params.update({"map_index": map_index})  # type: ignore[dict-item]

Review Comment:
   had to type ignore, otherwise am getting this one.
   ```
   task-sdk/src/airflow/sdk/api/client.py:263: error: Dict entry 0 has
   incompatible type "str": "int"; expected "str": "Union[str, list[str], None]" 
   [dict-item]
                   params.update({"map_index": map_index})
   
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063075925


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -664,12 +673,24 @@ def get_task_instance_states(
 
     results = session.scalars(query).all()
 
-    [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in results]
-
     if task_group_id:
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
-        [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in group_tasks]
+        if task_ids:
+            results = results + group_tasks
+        else:
+            results = group_tasks

Review Comment:
   Yeah updated , but if check is on task_ids, we have to return only task_group_id results when task_group_id provides otherwise we will return all results + task_group. 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2062935658


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -615,7 +619,11 @@ def get_task_instance_count(
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
         # Get unique (task_id, map_index) pairs
-        task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks]
+        if map_index is None:
+            task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks]
+        else:
+            task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks if ti.map_index == map_index]

Review Comment:
   ```suggestion
           task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks]
           if map_index is not None:
               task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks if ti.map_index == map_index]
   ```



##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -664,12 +673,24 @@ def get_task_instance_states(
 
     results = session.scalars(query).all()
 
-    [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in results]
-
     if task_group_id:
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
-        [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in group_tasks]
+        if task_ids:
+            results = results + group_tasks
+        else:
+            results = group_tasks

Review Comment:
   ```suggestion
           results = results + group_tasks if results else group_tasks
   ```



##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -245,6 +248,7 @@ def get_task_states(
         """Get task states given criteria."""
         params = {
             "dag_id": dag_id,
+            "map_index": map_index,

Review Comment:
   Add a check like this:
   ```
           if map_index is not None and map_index >= 0:
               params.update({"map_index": map_index})
   ```
   



##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -221,6 +222,7 @@ def get_count(
         """Get count of task instances matching the given criteria."""
         params = {
             "dag_id": dag_id,
+            "map_index": map_index,

Review Comment:
   Same here as below



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2064631513


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   >My usual recommendation is to only add migrations and new versions for breaking changes. Why don't we want it to be available in an older version?
   
   We do, but in this case it won't be available in Airflow 3.0.0 (the last released version) and will only be available in 3.0.1 though



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #49818:
URL: https://github.com/apache/airflow/pull/49818#issuecomment-2839732359

   ### Backport successfully created: v3-0-test
   
   <table>
                   <tr>
                       <th>Status</th>
                       <th>Branch</th>
                       <th>Result</th>
                   </tr>
                   <tr>
                       <td>✅</td>
                       <td>v3-0-test</td>
                       <td><a href="https://github.com/apache/airflow/pull/49979"><img src="https://img.shields.io/badge/PR-49979-blue" alt="PR Link"></a></td>
                   </tr>
               </table>


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063071163


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -615,7 +619,11 @@ def get_task_instance_count(
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
         # Get unique (task_id, map_index) pairs
-        task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks]
+        if map_index is None:
+            task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks]
+        else:
+            task_map_pairs = [(ti.task_id, ti.map_index) for ti in group_tasks if ti.map_index == map_index]

Review Comment:
   fixed.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "zmievsa (via GitHub)" <gi...@apache.org>.
zmievsa commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2064602871


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   My usual recommendation is to only add migrations and new versions for breaking changes. Why don't we want it to be available in an older version? 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063627682


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   We would also need a cadwyn migration. Look at the reverted changes in https://github.com/apache/airflow/pull/49116



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063627682


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   We would also need a cadwyn migration. Look at the reverted changes in https://github.com/apache/airflow/pull/49116



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan merged PR #49818:
URL: https://github.com/apache/airflow/pull/49818


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "zmievsa (via GitHub)" <gi...@apache.org>.
zmievsa commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2064655232


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   There's nothing bad about removing non-breaking changes in migrations so feel free to do this. But I'd suggest a versioning strategy that allows us to only remove breaking changes from old versions, if possible. 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2061308608


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -669,7 +681,14 @@ def get_task_instance_states(
     if task_group_id:
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
-        [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in group_tasks]
+        if map_index is None:

Review Comment:
   I have two questions here.
   
   1. Until now we were just returning the the response for the get_task_states with task ids like this i.e
   ```
   {
     "manual__2025-04-26T13:12:28.740030+00:0": {
       "start": "success",
       "example_group.example_python_op": "success",
       "example_group.add_one": "success"
     }
   }
   ```
   If we have dynamic tasks exists i am thinking to include those tasks like this?
   ```
   {
     "manual__2025-04-26T13:12:28.740030+00:0": {
       "start": "success",
       "example_group.example_python_op": "success",
       "example_group.add_one_0": "success",
       "example_group.add_one_1": "success",
       "example_group.add_one_2": "success"
     }
   }
   ```
   
   2. I think its a bug i feel at present , we return all the tasks states in response even when user provides input task_group_id. should i update this to return only those tasks under task_group. 
   
   
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2063071493


##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -245,6 +248,7 @@ def get_task_states(
         """Get task states given criteria."""
         params = {
             "dag_id": dag_id,
+            "map_index": map_index,

Review Comment:
   updated.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2061330517


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -669,7 +681,14 @@ def get_task_instance_states(
     if task_group_id:
         group_tasks = _get_group_tasks(dag_id, task_group_id, session, logical_dates, run_ids)
 
-        [run_id_task_state_map[task.run_id].update({task.task_id: task.state}) for task in group_tasks]
+        if map_index is None:

Review Comment:
   Fixed bug and response structure aswell to include dynamic tasks with  like task_id_0, task_id_1..



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on PR #49818:
URL: https://github.com/apache/airflow/pull/49818#issuecomment-2835779329

   @kaxil about cadwine migration comment, do we need to do it for this, is it manually i need to generate? 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2064495669


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   @zmievsa 👋 
   
   What's your suggestion to things like this, where a new optional param is added. Should we add a Cadwyn migration? Technically this isn't a breaking change but at the same time it isn't available in older versions.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "zmievsa (via GitHub)" <gi...@apache.org>.
zmievsa commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2064602871


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   My usual recommendation is to only add migrations and new versions for breaking changes. Why don't we want it to be available in an older version? 
   
   Btw the easiest way to version queries is to use the pydantic class-based syntax for queries that is discussed in fastAPI docs for queries. 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add map_index filter option to GetTICount and GetTaskStates [airflow]

Posted by "gopidesupavan (via GitHub)" <gi...@apache.org>.
gopidesupavan commented on code in PR #49818:
URL: https://github.com/apache/airflow/pull/49818#discussion_r2066827723


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -593,6 +593,7 @@ def get_previous_successful_dagrun(
 def get_task_instance_count(
     dag_id: str,
     session: SessionDep,
+    map_index: Annotated[int | None, Query()] = None,

Review Comment:
   So @kaxil we can merge this, no migration required? 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org