Skip to content

Fix BigQuery empty SELECT response typing#12258

Merged
StpMax merged 2 commits into
mindsdb:releases/26.1.0from
ianu82:codex/fix-bigquery-empty-select-response-type
Mar 20, 2026
Merged

Fix BigQuery empty SELECT response typing#12258
StpMax merged 2 commits into
mindsdb:releases/26.1.0from
ianu82:codex/fix-bigquery-empty-select-response-type

Conversation

@ianu82

@ianu82 ianu82 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • update BigQuery native_query to treat any dataframe result as RESPONSE_TYPE.TABLE, including empty rowsets
  • add a regression unit test covering empty SELECT behavior

Why

Empty SELECT queries produce dataframes with schema but no rows. Returning OK for these responses drops the table contract and breaks metadata/column-aware downstream logic.

Validation

  • python3 -m py_compile mindsdb/integrations/handlers/bigquery_handler/bigquery_handler.py tests/unit/handlers/test_bigquery.py
  • pytest -q tests/unit/handlers/test_bigquery.py -k empty_select_returns_table (fails in this environment due to missing optional dependency google.api_core)

@github-actions

github-actions Bot commented Feb 27, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

result = query.to_dataframe()
if not result.empty:
if isinstance(result, pd.DataFrame):
response = Response(RESPONSE_TYPE.TABLE, result)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correctness: ⚠️ This change makes the condition always true because to_dataframe() always returns a DataFrame, so you never return RESPONSE_TYPE.OK (e.g., for DDL/empty results). That’s a behavior regression from the previous not result.empty logic. Restore the empty check (optionally keep the type guard).

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In `mindsdb/integrations/handlers/bigquery_handler/bigquery_handler.py` around the `native_query` result handling, reintroduce the empty-result check so that non-result queries still return `RESPONSE_TYPE.OK`. Update the condition to `isinstance(result, pd.DataFrame) and not result.empty`.

@ianu82

ianu82 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed. I refined native_query result typing so non-result operations still return RESPONSE_TYPE.OK, while empty SELECT queries with schema still return RESPONSE_TYPE.TABLE.

Implemented condition:

  • isinstance(result, pd.DataFrame) and (not result.empty or len(result.columns) > 0)

Also added a regression test for the no-schema empty dataframe case (pd.DataFrame() -> OK) alongside the existing empty-select test (columns present -> TABLE).

@StpMax StpMax changed the base branch from main to releases/26.1.0 March 20, 2026 06:56
@StpMax StpMax merged commit d561f22 into mindsdb:releases/26.1.0 Mar 20, 2026
16 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants