Fix BigQuery empty SELECT response typing#12258
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
| result = query.to_dataframe() | ||
| if not result.empty: | ||
| if isinstance(result, pd.DataFrame): | ||
| response = Response(RESPONSE_TYPE.TABLE, result) |
There was a problem hiding this comment.
Correctness: 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`.
|
Addressed. I refined Implemented condition:
Also added a regression test for the no-schema empty dataframe case ( |
Summary
native_queryto treat any dataframe result asRESPONSE_TYPE.TABLE, including empty rowsetsWhy
Empty SELECT queries produce dataframes with schema but no rows. Returning
OKfor 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.pypytest -q tests/unit/handlers/test_bigquery.py -k empty_select_returns_table(fails in this environment due to missing optional dependencygoogle.api_core)