You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/09/06 08:06:00 UTC
[GitHub] [airflow] uranusjr commented on a diff in pull request #32646: Add task context logging feature to allow forwarding messages to task logs
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org