massucattoj opened a new pull request, #41996: URL: https://github.com/apache/superset/pull/41996
### SUMMARY Using Jinja templating in a Custom SQL filter (e.g. a `HAVING` clause) on a legacy chart such as the Time-series Table raises `Invalid SQL clause.` **Root cause.** The legacy viz pipeline validated filter clauses with SQLGlot *before* rendering Jinja, so the raw template text was parsed as SQL and rejected. This happened in two redundant places: 1. `split_adhoc_filters_into_base_filters` (`superset/utils/core.py`) 2. `BaseViz.query_obj()` (`superset/viz.py`) - re-sanitized the same clauses right after. The modern chart-data pipeline doesn't have this problem because it renders the template *before* validating (`QueryObject.validate()` → `processor.process_template(clause, force=True)` → `sanitize_clause`), which is why only legacy viz types were affected. **Fix.** Remove the premature validation instead of duplicating template rendering into the legacy pipeline. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF Before: <img width="1751" height="1319" alt="Screenshot 2026-07-13 at 08 04 09" src="https://github.com/user-attachments/assets/783282a1-e4ae-41db-9468-67420a70377f" /> After: <img width="1752" height="1311" alt="Screenshot 2026-07-13 at 07 57 07" src="https://github.com/user-attachments/assets/47fbfb6b-a3c3-4f2a-bb1f-8451121d5c15" /> ### TESTING INSTRUCTIONS Requires `ENABLE_TEMPLATE_PROCESSING: True`. 1. Create a Time-series Table chart using the "Vehicle Sales" (`cleaned_sales_data`) example dataset, with metric `SUM(price_each)` and one entry in "Time series columns". 2. Add a filter → Custom SQL → clause **HAVING** → `sum(price_each) > {% if filter_values('threshold')|length %} {{ filter_values('threshold')[0] }} {% else %} 0 {% endif %}` 3. Update the chart. - Before: `Invalid SQL clause` error. - After: chart renders; the issued query contains `HAVING ((sum(price_each) > 0))`. 4. Regression check - replace the filter with genuinely invalid SQL (e.g. `sum(price_each) > ) broken (`) and update: the query is still rejected, by the downstream validator (`INVALID_SQL_ERROR` with parse position). ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] Has associated issue: - [x] Required feature flags: `ENABLE_TEMPLATE_PROCESSING` - [ ] 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]
