fix(streaming-export): route SQL through mutate_sql_based_on_config#40495
Conversation
Code Review Agent Run #8705a4Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40495 +/- ##
==========================================
- Coverage 64.17% 64.17% -0.01%
==========================================
Files 2592 2592
Lines 139299 139300 +1
Branches 32347 32347
==========================================
Hits 89395 89395
- Misses 48367 48368 +1
Partials 1537 1537
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SUMMARY
Addresses Bug 1 of #40465. The streaming CSV export path (added in #35478) sends raw chart SQL directly to
connection.execute(text(sql))without first callingdatabase.mutate_sql_based_on_config(). Every other Superset execution site (SQL Lab, chart-data JSON, alerts, validators, helpers) routes SQL through that mutator so engine-spec / config transforms are applied.The most visible consequence is on Trino: the SQL Superset generates for a chart ends with
LIMIT N;, and Trino's HTTP statement endpoint rejects trailing semicolons withmismatched input ';'. Expecting: <EOF>. Because the streaming response has already flushed headers by the time the exception fires, the user receives an HTTP 200 with the sentinel__STREAM_ERROR__: Export failed...written into what should have been their CSV file.Fix
In
superset/commands/streaming_export/base.py::_execute_query_and_stream, run the SQL through the same mutator the non-streaming paths use:TESTING INSTRUCTIONS
pytest tests/unit_tests/commands/chart/streaming_export_command_test.py \ tests/unit_tests/commands/sql_lab/streaming_export_command_test.py -vtest_streaming_sql_is_mutated_before_executeconfirmsmutate_sql_based_on_configis called with the raw chart SQL and that the mutated string is whatconnection.executereceives.Result locally: 28 / 28 pass.
Out of scope (Bug 2 from #40465)
The issue also reports that user impersonation is bypassed on the streaming path — every export shows up in the Trino query log as the service principal regardless of which Superset user triggered it. Verifying that requires reproducing against an impersonation-enabled Trino, which is out of scope for this PR. Tracking separately so the security-sensitive change gets its own review.
ADDITIONAL INFORMATION