ashb commented on a change in pull request #17719:
URL: https://github.com/apache/airflow/pull/17719#discussion_r692754650
##########
File path: airflow/cli/commands/task_command.py
##########
@@ -51,15 +51,17 @@
from airflow.utils.session import create_session, provide_session
-def _get_ti(task, exec_date_or_run_id):
+@provide_session
+def _get_ti(task, exec_date_or_run_id, session):
"""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)
+ dag_run = task.dag.get_dagrun(run_id=exec_date_or_run_id, session=session)
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
+ dag_run.session.query(DagRun).filter(
+ DagRun.dag_id == task.dag_id,
+ DagRun.execution_date == execution_date,
+ ).one()
except (ParserError, TypeError):
Review comment:
These can happen from the `timezone.parse` on L60, but yes we should add
NoResultFound too
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]