houqp commented on a change in pull request #10917:
URL: https://github.com/apache/airflow/pull/10917#discussion_r518227202



##########
File path: airflow/models/taskinstance.py
##########
@@ -1446,18 +1454,21 @@ def handle_failure(self, error, test_mode=None, 
context=None, force_fail=False,
                 self.log.error('Failed to send email to: %s', task.email)
                 self.log.exception(exec2)
 
-        # Handling callbacks pessimistically
-        if callback:
-            try:
-                callback(context)
-            except Exception as exec3:  # pylint: disable=broad-except
-                self.log.error("Failed at executing callback")
-                self.log.exception(exec3)
-
         if not test_mode:
             session.merge(self)
         session.commit()
 
+    @provide_session
+    def handle_failure_with_callback(
+        self,
+        error,
+        test_mode=None,
+        force_fail: bool = False,
+        session=None,

Review comment:
       @turbaszek added type hints for error and test_mode, but leaving out 
session since I am not sure what's the best way to handle because it's not 
supposed to be `Optional[Session]` due to the provide_session decorator. But on 
the other hand we need to set the default value to `None` so the 
provide_session operator knows when to inject the session.

##########
File path: airflow/models/taskinstance.py
##########
@@ -1446,18 +1454,21 @@ def handle_failure(self, error, test_mode=None, 
context=None, force_fail=False,
                 self.log.error('Failed to send email to: %s', task.email)
                 self.log.exception(exec2)
 
-        # Handling callbacks pessimistically
-        if callback:
-            try:
-                callback(context)
-            except Exception as exec3:  # pylint: disable=broad-except
-                self.log.error("Failed at executing callback")
-                self.log.exception(exec3)
-
         if not test_mode:
             session.merge(self)
         session.commit()
 
+    @provide_session
+    def handle_failure_with_callback(
+        self,
+        error,
+        test_mode=None,
+        force_fail: bool = False,
+        session=None,

Review comment:
       @turbaszek added type hints for error and test_mode, but leaving out 
session since I am not sure what's the best way to handle because it's not 
supposed to be `Optional[Session]` due to use of provide_session decorator. But 
on the other hand we need to set the default value to `None` so the 
provide_session operator knows when to inject the session.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to