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

   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   `SqlResultExportCommand.validate()`, used by the SQL Lab CSV export 
endpoint, calls `self._query.raise_for_access()`. 
   This call is currently guarded only against `SupersetSecurityException`.
   
   `raise_for_access()` may re-parse the query’s unrendered Jinja through 
`process_jinja_sql()`. If the template is invalid for example, because of an 
unclosed `{% if %}` this can raise a raw `jinja2.exceptions.TemplateError`. 
Because the error isn’t caught, it results in an opaque HTTP 500 response 
instead of a structured client error.
   
   Other call sites in the same subsystem already handle this case. 
`superset/sqllab/api.py`, `superset/commands/sql_lab/estimate.py`, and 
`superset/commands/sql_lab/results.py` catch `TemplateError` around the same 
`raise_for_access()` call. 
   
   This behavior was introduced in #43145, where `export.py` was listed as a 
follow-up but was missed.
   
   This change adds an `except TemplateError` clause alongside the existing 
`SupersetSecurityException` handler in `validate()`. 
   It raises a `SupersetErrorException` with `status=400` and 
`error_type=GENERIC_COMMAND_ERROR`, matching the existing implementation in the 
other SQL Lab paths.
   
   This is an additive error-handling change only. Existing success and failure 
paths remain unchanged.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   - No B/A
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   * Added `TestSqlResultExportCommand.test_validation_malformed_jinja` to 
`tests/integration_tests/sql_lab/commands_tests.py`. The test follows the 
existing `test_validation_malformed_jinja` in `TestSqlExecutionResultsCommand`.
   
   * Run the integration tests:
   
     ```bash
     pytest tests/integration_tests/sql_lab/commands_tests.py -q
     ```
   
   * To test manually:
   
   1. Enable `ENABLE_TEMPLATE_PROCESSING`.
   2. In SQL Lab, run a query containing malformed Jinja, such as an unclosed 
`{% if %}`.
   3. Export the results as CSV.
   4. Confirm that the request returns a `400` response with a clear error 
message instead of a `500`.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] 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