moomindani opened a new pull request, #69230:
URL: https://github.com/apache/airflow/pull/69230

   Fixes a `TypeError` in `DatabricksSqlHook.run()` when a scalar handler is 
used and the query returns no rows.
   
   DBAPI `fetchone()` returns `None` on an empty result set, and common.sql's 
`fetch_one_handler` is typed `-> tuple | None` accordingly (it also returns 
`None` for statements where `cursor.description` is `None`). The base 
`DbApiHook._make_common_data_structure` passes `None` through unchanged, and 
`DbApiHook.run()` is annotated `... | None`. The Databricks override, however, 
only accepted `Row` or `Sequence[Row]` and raised `TypeError: Expected 
Sequence[Row] or Row, but got <class 'NoneType'>`.
   
   User-visible impact: `DatabricksSqlHook.get_first(...)` — which is just 
`run(handler=fetch_one_handler)` — crashed on any query returning no rows, 
where every non-overriding `DbApiHook` (postgres, snowflake, ...) returns 
`None`. With this change the Databricks hook follows the common.sql contract 
and passes `None` through.
   
   (The odbc hook's override maps falsy results to `[]` instead; `None` is 
deliberately chosen here to preserve `fetchone` semantics — "no row" and "empty 
row set" stay distinguishable — and to match the base contract.)
   
   Found while validating #39448 against a live Databricks SQL warehouse; 
verified there that with this change `run(..., handler=fetch_one_handler)` on 
an empty result returns `None` and serializes cleanly through XCom.
   
   related: #39448
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Fable 5)
   
   Generated-by: Claude Code (Fable 5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to