malthe commented on a change in pull request #21993:
URL: https://github.com/apache/airflow/pull/21993#discussion_r819578828



##########
File path: airflow/models/taskinstance.py
##########
@@ -1746,14 +1745,23 @@ def handle_failure(
 
         if error:
             if isinstance(error, BaseException):
-                execution_frame = _EXECUTION_FRAME_MAPPING.get(self.task)
                 tb = error.__traceback__
-                while tb is not None:
-                    if tb.tb_frame is execution_frame:
+                try:
+                    execution_frame = _LAST_FRAME_LOCAL_STORAGE.frame
+                    _LAST_FRAME_LOCAL_STORAGE.frame = None
+                    while tb is not None:
+                        if tb.tb_frame is execution_frame:
+                            tb = tb.tb_next
+                            break
                         tb = tb.tb_next
-                        break
-                    tb = tb.tb_next
-                tb = tb or error.__traceback__
+                    tb = tb or error.__traceback__
+                except AttributeError:

Review comment:
       It feels perhaps like nitpicking, but the stuff we're worried about here 
is getting the frame and making sure that it's set.
   
   This code doesn't actually raise an error if it is set but is `None` and the 
try/except could and should be limited to the code that we believe could lead 
to an error.
   
   The `while` loop here should never cause an error.




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