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


##########
airflow/models/taskinstance.py:
##########
@@ -736,17 +736,15 @@ def current_state(self, session: Session = NEW_SESSION) 
-> str:
         we use and looking up the state becomes part of the session, otherwise
         a new session is used.
 
+        sqlalchemy.inspect is used here to get the primary keys ensuring that 
if they change
+        it will not regress 
+
         :param session: SQLAlchemy ORM Session
         """
-        return (
-            session.query(TaskInstance.state)
-            .filter(
-                TaskInstance.dag_id == self.dag_id,
-                TaskInstance.task_id == self.task_id,
-                TaskInstance.run_id == self.run_id,
-            )
-            .scalar()
-        )
+        query = session.query(TaskInstance.state)
+        for col in inspect(TaskInstance).primary_key:
+            query = query.filter(col == getattr(self, col.name))
+        return query.scalar()

Review Comment:
   ```suggestion
           filters = (col == getattr(self, col.name) for col in 
inspect(TaskInstance).primary_key)
           return session.query(TaskInstance.state).filter(*filters).scalar()
   
   ```



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

Reply via email to