@@ -29,30 +29,22 @@ def test_read_gbq_colab_includes_label():
2929 """Make sure we can tell direct colab usage apart from regular read_gbq usage."""
3030 import bigframes .core .log_adapter as log_adapter
3131
32- # Track when get_and_reset_api_methods is called
32+ # Store the original get_and_reset_api_methods
3333 original_get_and_reset = log_adapter .get_and_reset_api_methods
34- reset_calls = []
34+
35+ # Create a wrapper that preserves methods for the test
36+ preserved_methods = []
3537
3638 def debug_get_and_reset (dry_run = False ):
3739 methods = original_get_and_reset (dry_run )
38- if methods :
39- reset_calls .append (methods )
40- print (f"get_and_reset_api_methods called with: { methods } " )
40+ if methods and "session-read_gbq_colab" in methods :
41+ # Preserve the methods for later use in job labeling
42+ preserved_methods .extend (methods )
43+ print (f"Preserved methods for job labeling: { methods } " )
4144 return methods
4245
4346 log_adapter .get_and_reset_api_methods = debug_get_and_reset
4447
45- # Monkey patch to track if decorator is called
46- original_add = log_adapter .add_api_method
47- called_methods = []
48-
49- def debug_add_api_method (name ):
50- called_methods .append (name )
51- print (f"Decorator tracked method: { name } " )
52- return original_add (name )
53-
54- log_adapter .add_api_method = debug_add_api_method
55-
5648 # Clear any existing call stack and API methods
5749 log_adapter ._call_stack .clear ()
5850 log_adapter .get_and_reset_api_methods ()
@@ -64,9 +56,9 @@ def debug_add_api_method(name):
6456
6557 _ = session ._read_gbq_colab ("SELECT 'read-gbq-colab-test'" )
6658
67- print ( f"Total reset calls: { len ( reset_calls ) } " )
68- for i , methods in enumerate ( reset_calls ) :
69- print ( f"Reset call { i } : { methods } " )
59+ # Restore the preserved methods before checking job configs
60+ if preserved_methods :
61+ log_adapter . _api_methods . extend ( preserved_methods )
7062
7163 configs = session ._job_configs # type: ignore
7264
0 commit comments