Skip to content

Commit 129cdb7

Browse files
committed
fix: handle ReferenceError in BigQueryAgentAnalyticsPlugin atexit cleanup
- Add try/except to catch ReferenceError when weakref proxy object is already garbage collected - Prevents CI failure due to unhandled exception during test cleanup
1 parent 4ec240d commit 129cdb7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/google/adk/plugins/bigquery_agent_analytics_plugin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,13 @@ def get_credentials():
14561456
def _atexit_cleanup(batch_processor: "BatchProcessor") -> None:
14571457
"""Clean up batch processor on script exit."""
14581458
# Check if the batch_processor object is still alive
1459-
if batch_processor and not batch_processor._shutdown:
1459+
# weakref.proxy raises ReferenceError if the referent has been garbage collected
1460+
try:
1461+
is_alive = batch_processor and not batch_processor._shutdown
1462+
except ReferenceError:
1463+
# Object has already been garbage collected, nothing to clean up
1464+
return
1465+
if is_alive:
14601466
# Emergency Flush: Rescue any logs remaining in the queue
14611467
remaining_items = []
14621468
try:

0 commit comments

Comments
 (0)