jenwitteng opened a new pull request, #42127:
URL: https://github.com/apache/superset/pull/42127

   ### SUMMARY
   
   `Database._execute_sql_with_mutation_and_logging` captured 
`cursor.description` **before** calling `db_engine_spec.fetch_data(cursor)`. 
Some asynchronous DB-API drivers — notably Spark Thrift — expose *placeholder* 
column metadata (a single `Result` column of type `STRING`) until a fetch call 
waits for the async operation to complete. As a result, charts and queries 
executed against such databases received incorrect column names and types.
   
   This moves the `description = cursor.description` capture to run **after** 
`fetch_data`, so the real column metadata is read once the operation has 
resolved.
   
   Two properties are preserved:
   
   - The capture stays inside the `with self.get_raw_connection() as conn:` 
block, so the Databricks fix from #34906 (which required reading `description` 
before the connection closes) is not regressed.
   - This aligns with `BaseEngineSpec.fetch_data`, which already reads 
`cursor.description` *after* `cursor.fetchall()`.
   
   Per DB-API 2.0, `cursor.description` remains valid after `execute` until the 
next `execute`, and fetching does not reset it, so this reordering is safe for 
synchronous drivers.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Not applicable (backend-only change). Behaviorally, on affected async 
engines:
   
   - **Before:** result columns show placeholder metadata (single `Result` 
column, type `STRING`).
   - **After:** result columns show the query's actual names and types.
   
   ### TESTING INSTRUCTIONS
   
   Added 
`tests/unit_tests/models/core_test.py::test_get_df_captures_description_after_fetch`,
 which simulates an async cursor whose `description` transitions from a 
placeholder to the real metadata during `fetch_data`, and asserts the captured 
description reflects the post-fetch value. The test fails under the previous 
before-fetch ordering and passes with this change.
   
   ```
   pytest tests/unit_tests/models/core_test.py -k 
captures_description_after_fetch
   ```
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to