You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/05 14:16:09 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #21965: Mapped task instance endpoint

uranusjr commented on a change in pull request #21965:
URL: https://github.com/apache/airflow/pull/21965#discussion_r820108710



##########
File path: airflow/api_connexion/endpoints/task_instance_endpoint.py
##########
@@ -86,6 +87,64 @@ def get_task_instance(
             RTIF.task_id == TI.task_id,
         ),
     ).add_entity(RTIF)
+
+    try:
+        task_instance = query.one_or_none()
+    except MultipleResultsFound:
+        raise NotFound(
+            "Task instance not found", detail="Task instance is mapped, add the map_index value to the URL"
+        )
+    if task_instance is None:
+        raise NotFound("Task instance not found")
+    if task_instance[0].map_index != -1:
+        raise NotFound(
+            "Task instance not found", detail="Task instance is mapped, add the map_index value to the URL"
+        )
+
+    return task_instance_schema.dump(task_instance)
+
+
+@security.requires_access(
+    [
+        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
+        (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
+    ],
+)
+@provide_session
+def get_mapped_task_instance(
+    *,
+    dag_id: str,
+    dag_run_id: str,
+    task_id: str,
+    map_index: int,
+    session: Session = NEW_SESSION,
+) -> APIResponse:
+    """Get task instance"""
+    query = (
+        session.query(TI)
+        .filter(
+            TI.dag_id == dag_id, DR.run_id == dag_run_id, TI.task_id == task_id, TI.map_index == map_index

Review comment:
       I don’t think there’s an actual difference (we need to join the DagRun table anyway), but it is just more consistent to always use the fields on the TI 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