mik-laj commented on a change in pull request #9597:
URL: https://github.com/apache/airflow/pull/9597#discussion_r448586807



##########
File path: airflow/api_connexion/endpoints/task_instance_endpoint.py
##########
@@ -14,23 +14,110 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from typing import Any, List, Optional, Tuple
 
-# TODO(mik-laj): We have to implement it.
-#     Do you want to help? Please look at: 
https://github.com/apache/airflow/issues/8132
+from sqlalchemy import and_, func, or_
 
+from airflow.api_connexion.exceptions import NotFound
+from airflow.api_connexion.parameters import format_datetime, format_parameters
+from airflow.api_connexion.schemas.task_instance_schema import (
+    TaskInstanceCollection, task_instance_collection_schema, 
task_instance_schema,
+)
+from airflow.models.dagrun import DagRun as DR
+from airflow.models.taskinstance import TaskInstance as TI
+from airflow.utils.session import provide_session
+
+
+@provide_session
+def get_task_instance(dag_id: str, dag_run_id: str, task_id: str, 
session=None):
+    query = (
+        session.query(TI)
+        .filter(TI.dag_id == dag_id)
+        .join(DR, and_(TI.dag_id == DR.dag_id, TI.execution_date == 
DR.execution_date))
+        .filter(DR.run_id == dag_run_id)
+        .filter(TI.task_id == task_id)
+    )
+
+    task_instance = query.one_or_none()
+
+    if task_instance is None:
+        raise NotFound("Task instance not found")

Review comment:
       Yes. This is handled by connexion.
   https://connexion.readthedocs.io/en/latest/exceptions.html




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

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


Reply via email to