Skip to content

Commit 0ccc43c

Browse files
na0fu3ycopybara-github
authored andcommitted
fix: Fix error when query job destination is None
Merge #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=#3127 from na0fu3y:patch-1 69218a8 PiperOrigin-RevId: 829270885
1 parent a0cf97e commit 0ccc43c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/google/adk/tools/bigquery/query_tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def _execute_sql(
127127
)
128128
if (
129129
dry_run_query_job.statement_type != "SELECT"
130+
and dry_run_query_job.destination
130131
and dry_run_query_job.destination.dataset_id != bq_session_dataset_id
131132
):
132133
return {

0 commit comments

Comments
 (0)