kaxil commented on a change in pull request #16030:
URL: https://github.com/apache/airflow/pull/16030#discussion_r646568767



##########
File path: airflow/cli/commands/task_command.py
##########
@@ -42,9 +45,27 @@
     get_dags,
     suppress_logs_and_warning,
 )
+from airflow.utils.dates import timezone
 from airflow.utils.log.logging_mixin import StreamLogWriter
 from airflow.utils.net import get_hostname
-from airflow.utils.session import create_session
+from airflow.utils.session import create_session, provide_session
+
+
+def _get_ti(task, exec_date_or_run_id):
+    """Get the task instance through DagRun.run_id, if that fails, get the TI 
the old way"""
+    dag_run = task.dag.get_dagrun(run_id=exec_date_or_run_id)
+    if not dag_run:
+        try:
+            execution_date = timezone.parse(exec_date_or_run_id)
+            ti = TaskInstance(task, execution_date)
+            ti.refresh_from_db()
+            return ti
+        except (ParserError, TypeError):
+            raise AirflowException(f"DagRun with run_id: {exec_date_or_run_id} 
not found")
+    ti = dag_run.get_task_instance(task.task_id)
+    ti.task = task
+    ti.refresh_from_db()

Review comment:
       Do we need this call ? Since L65 gets TI from DB itself, this feels 
redundant unless I am missing something




-- 
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:
[email protected]


Reply via email to