This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 7233ffe644 Make traceback for DB isolation mode way smaller and useful 
(#41129)
7233ffe644 is described below

commit 7233ffe64406f32f9cff79d563cf636c2fb812de
Author: Jarek Potiuk <[email protected]>
AuthorDate: Tue Jul 30 21:58:42 2024 +0200

    Make traceback for DB isolation mode way smaller and useful (#41129)
    
    Removes a lot of useless frames from the traceback:
    
    * pytest and pluggy
    * last two "create_session" tracebacks
    
    This way it is immediately visible where we should look for problems
    
    Related: #41067
---
 airflow/settings.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/airflow/settings.py b/airflow/settings.py
index e1915ab807..d76f2c148e 100644
--- a/airflow/settings.py
+++ b/airflow/settings.py
@@ -267,6 +267,15 @@ class SkipDBTestsSession:
         pass
 
 
+def get_cleaned_traceback(stack_summary: traceback.StackSummary) -> str:
+    clened_traceback = [
+        frame
+        for frame in stack_summary[:-2]
+        if "/_pytest" not in frame.filename and "/pluggy" not in frame.filename
+    ]
+    return "".join(traceback.format_list(clened_traceback))
+
+
 class TracebackSession:
     """
     Session that throws error when you try to use it.
@@ -284,7 +293,7 @@ class TracebackSession:
             "TracebackSession object was used but internal API is enabled. "
             "You'll need to ensure you are making only RPC calls with this 
object. "
             "The stack list below will show where the TracebackSession object 
was created."
-            + "\n".join(traceback.format_list(self.traceback))
+            + get_cleaned_traceback(self.traceback)
         )
 
     def remove(*args, **kwargs):
@@ -324,9 +333,9 @@ class TracebackSessionForTests:
             f"     {frame_summary.line}\n\n"
             "You'll need to ensure you are making only RPC calls with this 
object. "
             "The stack list below will show where the TracebackSession object 
was called:\n"
-            + "".join(traceback.format_list(self.traceback))
+            + get_cleaned_traceback(self.traceback)
             + "\n\nThe stack list below will show where the TracebackSession 
object was created:\n"
-            + "".join(traceback.format_list(self.created_traceback))
+            + get_cleaned_traceback(self.created_traceback)
         )
 
     def remove(*args, **kwargs):

Reply via email to