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


##########
airflow/models/taskinstance.py:
##########
@@ -895,6 +895,19 @@ def refresh_from_db(self, session: Session = NEW_SESSION, 
lock_for_update: bool
         else:
             self.state = None
 
+    @classmethod
+    def get_by_key(cls, ti_key, session) -> TaskInstance:
+        return (
+            session.query(TaskInstance)
+            .filter(
+                TaskInstance.task_id == ti_key.task_id,
+                TaskInstance.dag_id == ti_key.dag_id,
+                TaskInstance.run_id == ti_key.run_id,
+                TaskInstance.map_index == ti_key.map_index,
+            )
+            .one_or_none()
+        )

Review Comment:
   Don’t particularly like this. Putting all accessors on the model class 
should be considered an antipattern (search for how the active record pattern 
violates the single responsibility principle for details). I know Airflow 
already does this a lot, but let’s not pile on this.



##########
airflow/models/taskinstance.py:
##########
@@ -895,6 +895,19 @@ def refresh_from_db(self, session: Session = NEW_SESSION, 
lock_for_update: bool
         else:
             self.state = None
 
+    @classmethod
+    def get_by_key(cls, ti_key, session) -> TaskInstance:
+        return (
+            session.query(TaskInstance)
+            .filter(
+                TaskInstance.task_id == ti_key.task_id,
+                TaskInstance.dag_id == ti_key.dag_id,
+                TaskInstance.run_id == ti_key.run_id,
+                TaskInstance.map_index == ti_key.map_index,
+            )
+            .one_or_none()
+        )

Review Comment:
   Don’t particularly like this. Putting all accessors on the model class 
should be considered an antipattern (search for how the active record pattern 
violates the single responsibility principle for details). I know Airflow 
already does this a lot, but let’s not pile on this.



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