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


##########
airflow/models/dag.py:
##########
@@ -1378,6 +1379,33 @@ def normalized_schedule_interval(self) -> 
ScheduleInterval:
             _schedule_interval = self.schedule_interval
         return _schedule_interval
 
+    @staticmethod
+    @internal_api_call
+    @provide_session
+    def fetch_callback(
+        dag: DAG, dagrun: DagRun | DagRunPydantic, success=True, reason=None, 
session=NEW_SESSION
+    ):
+        """
+        Fetch the appropriate callbacks depending on the value of success, 
namely the
+        on_failure_callback or on_success_callback. This method gets the 
context of a
+        single TaskInstance part of this DagRun and returns it along the list 
of callbacks.
+
+        :param dag: DAG object
+        :param dagrun: DagRun object
+        :param success: Flag to specify if failure or success callback should 
be called
+        :param reason: Completion reason
+        :param session: Database session
+        """
+        callbacks = dag.on_success_callback if success else 
dag.on_failure_callback
+        if callbacks:
+            callbacks = callbacks if isinstance(callbacks, list) else 
[callbacks]
+            tis = dagrun.get_task_instances(session=session)
+            ti = tis[-1]  # get first TaskInstance of DagRun

Review Comment:
   This is unnecessarily costly. Doing a `session...one()` here would be better.



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