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/04/06 01:41:13 UTC

[GitHub] [airflow] jedcunningham commented on a diff in pull request #22764: No need to load whole ti in current_state

jedcunningham commented on code in PR #22764:
URL: https://github.com/apache/airflow/pull/22764#discussion_r843389686


##########
airflow/models/taskinstance.py:
##########
@@ -723,20 +723,16 @@ def current_state(self, session=NEW_SESSION) -> str:
 
         :param session: SQLAlchemy ORM Session
         """
-        ti = (
-            session.query(TaskInstance)
+        state = (

Review Comment:
   ```suggestion
           return (
   ```
   
   I think this would work, and is even simpler? (Sorry, has to be across 3 suggestions 🤷‍♂️)



##########
airflow/models/taskinstance.py:
##########
@@ -723,20 +723,16 @@ def current_state(self, session=NEW_SESSION) -> str:
 
         :param session: SQLAlchemy ORM Session
         """
-        ti = (
-            session.query(TaskInstance)
+        state = (
+            session.query(TaskInstance.state)
             .filter(
                 TaskInstance.dag_id == self.dag_id,
                 TaskInstance.task_id == self.task_id,
                 TaskInstance.run_id == self.run_id,
             )
-            .all()
+            .one_or_none()

Review Comment:
   ```suggestion
               .scalar()
   ```



##########
airflow/models/taskinstance.py:
##########
@@ -723,20 +723,16 @@ def current_state(self, session=NEW_SESSION) -> str:
 
         :param session: SQLAlchemy ORM Session
         """
-        ti = (
-            session.query(TaskInstance)
+        state = (
+            session.query(TaskInstance.state)
             .filter(
                 TaskInstance.dag_id == self.dag_id,
                 TaskInstance.task_id == self.task_id,
                 TaskInstance.run_id == self.run_id,
             )
-            .all()
+            .one_or_none()
         )
-        if ti:
-            state = ti[0].state
-        else:
-            state = None
-        return state
+        return state[0]

Review Comment:
   ```suggestion
   ```



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