From 0ccc43cf49dc0882dc896455d6603a602d8a28e7 Mon Sep 17 00:00:00 2001 From: Naofumi Yamada Date: Thu, 6 Nov 2025 22:27:35 -0800 Subject: [PATCH] fix: Fix error when query job destination is None Merge https://github.com/google/adk-python/pull/3127 # What this PR does This PR fixes a bug in the `execute_sql function` within `bigquery/query_tool.py`. The bug caused an error when executing queries that do not return a result set, such as a `CREATE TEMP FUNCTION` statement. # The problem Within `execute_sql,` when a user executed a query that doesn't produce a result set, like the following: ```sql CREATE TEMP FUNCTION f() AS (0); SELECT f(); ``` The corresponding BigQuery job object would have its `destination` property set to `None`. This caused an error because the code was written with the expectation of a valid destination table. # The solution The fix modifies `execute_sql` to check if the `query_job.destination` is None. If it is, the function correctly identifies the query as a statement that doesn't require a destination and allows it to complete successfully. This ensures that `execute_sql` can robustly handle these types of queries. COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3127 from na0fu3y:patch-1 69218a8d25699dfa2e18bb305087f01192e91e91 PiperOrigin-RevId: 829270885 --- src/google/adk/tools/bigquery/query_tool.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/google/adk/tools/bigquery/query_tool.py b/src/google/adk/tools/bigquery/query_tool.py index 6a73d324..23382579 100644 --- a/src/google/adk/tools/bigquery/query_tool.py +++ b/src/google/adk/tools/bigquery/query_tool.py @@ -127,6 +127,7 @@ def _execute_sql( ) if ( dry_run_query_job.statement_type != "SELECT" + and dry_run_query_job.destination and dry_run_query_job.destination.dataset_id != bq_session_dataset_id ): return {