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



##########
File path: airflow/cli/commands/task_command.py
##########
@@ -42,9 +45,29 @@
     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(dag, 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 = dag.get_dagrun(run_id=exec_date_or_run_id)
+    if not dag_run:
+        try:
+            execution_date = timezone.parse(exec_date_or_run_id)
+            # print("Warning: execution_date will be removed in
+            # tasks command in the future. Please use DagRun.run_id")
+            ti = TaskInstance(task, execution_date)

Review comment:
       I was wondering if it makes sense to add `ti.refresh_from_db()` in to 
this path, and I think probably yes, even though only one of the tasks _needs_ 
it, this makes it predictable I think.
   
   We can then remove the call on L250.
   
   Thoughts?




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