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/06/22 04:44:32 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

uranusjr commented on code in PR #24592:
URL: https://github.com/apache/airflow/pull/24592#discussion_r903276343


##########
airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -125,9 +125,9 @@ def _render_log_id(self, ti: TaskInstance, try_number: int) -> str:
             else:
                 log_id_template = self.log_id_template
 
-        dag = ti.task.dag
-        assert dag is not None  # For Mypy.
         try:
+            dag = ti.task.dag
+            assert dag is not None  # For Mypy.
             data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
         except AttributeError:  # ti.task is not always set.

Review Comment:
   Judging from the comment on the `except` clause, this should be
   
   ```python
   try:
       dag = ti.task.dag
   except AttributeError:  # ti.task is not always set.
       ...
   else:
       assert dag is not None  # For Mypy.
       data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
   ```
   
   instead.



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