Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/google/adk/tools/bigquery/query_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ def execute_sql(
connection_properties=bq_connection_properties,
),
)
destination_dataset_id = None
if dry_run_query_job.destination:
destination_dataset_id = dry_run_query_job.destination.dataset_id

if (
dry_run_query_job.statement_type != "SELECT"
and dry_run_query_job.destination.dataset_id != bq_session_dataset_id
and destination_dataset_id != bq_session_dataset_id
and destination_dataset_id is not None
):
Comment on lines +197 to 205

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the current implementation correctly fixes the bug, it can be simplified for better readability and conciseness. By leveraging Python's short-circuiting behavior with and, you can perform the check for dry_run_query_job.destination and access its dataset_id within the same conditional expression. This avoids creating a temporary variable and makes the logic more direct.

      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 {
"status": "ERROR",
Expand Down
Loading