prathamesh04 opened a new pull request, #42412:
URL: https://github.com/apache/superset/pull/42412
### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
The streaming CSV export path (introduced by #35478) bypassed two critical
steps that all non-streaming export paths perform:
1. **SQL mutation bypass** — `database.mutate_sql_based_on_config()` was
never called,
leaving trailing semicolons unstripped for engines like Trino that reject
them,
causing all streaming CSV exports to crash with `__STREAM_ERROR__`.
2. **User impersonation bypass** — the path used `get_sqla_engine()`
directly instead
of `get_raw_connection()`, which bypasses `ENGINE_CONTEXT_MANAGER`. On
databases
with `impersonate_user: true` (Trino, Presto, etc.), all streaming CSV
exports
ran as the service principal, breaking audit trails and potentially
bypassing
per-user authorization (Ranger, OPA, RLS views).
This fix:
- Calls `database.mutate_sql_based_on_config(sql)` before execution
- Uses `get_raw_connection()` instead of `get_sqla_engine()` directly, which
handles
SSH tunnels, OAuth2, and user impersonation
- Executes via raw DBAPI cursor (same `fetchmany()` interface)
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
**Before:** Streaming CSV exports crash on Trino with `__STREAM_ERROR__:
Export failed` and run as the service principal.
**After:** Streaming CSV exports succeed and run as the logged-in user
(matching the non-streaming Excel export behavior).
### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
1. Connect Superset to a Trino/Presto database with `impersonate_user: true`
2. Create a chart backed by the Trino dataset
3. Click `...` → `Download` → `Export to CSV`
4. Verify the CSV contains data (not `__STREAM_ERROR__`)
5. Check Trino query history shows the logged-in user (not service principal)
Also run: `pytest
tests/unit_tests/commands/chart/streaming_export_command_test.py -v`
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
- [x] Has associated issue: #40465
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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]