rusackas opened a new pull request, #41870:
URL: https://github.com/apache/superset/pull/41870
### SUMMARY
Calculated column expressions with Jinja templates render correctly in
SELECT/WHERE/GROUP BY, but not when the calculated column is referenced by a
SIMPLE adhoc metric (e.g. `MAX(calc_col)`) used in `ORDER BY`. `get_sqla_query`
builds the `ORDER BY` expression via `adhoc_metric_to_sqla`, but that
particular call site wasn't passed the `template_processor`, so the underlying
`TableColumn`'s Jinja never got rendered and the raw `{% ... %}` / `{{ ... }}`
leaked into the generated SQL.
This adds a failing-first integration test that pins the bug (a SIMPLE adhoc
metric aggregating a Jinja-templated calculated column, used in `orderby`),
then fixes it by threading `template_processor` through at that call site. This
is a no-op for the SQL-expression adhoc metric type, since that branch's
`sqlExpression` is already rendered earlier in `get_sqla_query`.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend SQL generation change)
### TESTING INSTRUCTIONS
- `pytest tests/integration_tests/db_engine_specs/base_engine_spec_tests.py
-k calculated_column_in_order_by`
- The new `test_jinja_calculated_column_in_order_by` test fails on `master`
(raw `{{ ... }}` shows up in the rendered `ORDER BY` clause) and passes with
this fix.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #29378
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
Fixes #29378
--
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]