fix(dataset): calculated columns in virtual datasets fail when used as dynamic aggregation filter dimensions#39004
Conversation
…_column_to_sqla
Calculated columns on virtual datasets fail when used as dynamic aggregation
filter dimensions because get_column() was called with the raw Jinja template
string instead of the rendered column name. Pre-rendering via a dedicated helper
(_render_adhoc_expression_for_metadata_lookup) ensures expressions like
{{ filter_values('x')[0] }} resolve to the calculated column name before the
metadata lookup, so the column's CASE expression is inlined correctly rather
than falling back to literal_column.
Also fixes Mapped[SqlaTable] forward references to use quoted strings and
renames tbl, _ to tbl, _unused_cte to avoid shadowing the lazy_gettext
translation function.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39004 +/- ##
==========================================
- Coverage 64.42% 64.14% -0.29%
==========================================
Files 2536 2536
Lines 131103 131951 +848
Branches 30434 30743 +309
==========================================
+ Hits 84467 84635 +168
- Misses 45173 45806 +633
- Partials 1463 1510 +47
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:
|
Code Review Agent Run #daab6fActionable Suggestions - 0Review 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 |
|
🎪 Showtime deployed environment on GHA for 20d8ad3 • Environment: http://34.220.112.132:8080 (admin/admin) |
|
🎪 Showtime deployed environment on GHA for 20d8ad3 • Environment: http://35.91.242.246:8080 (admin/admin) |
…s dynamic aggregation filter dimensions (apache#39004) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

SUMMARY
This PR fixes a regression introduced in #36215, where
adhoc_column_to_sqlawas refactored to perform a metadata lookup (get_column) before rendering Jinja templates. As a result, templated expressions (e.g. usingfilter_values) were passed as raw strings, preventing calculated columns from being matched and expanded from dataset metadata, and instead falling back toliteral_column, which breaks for virtual datasets.This change restores the correct order by rendering the template first (via a dedicated helper
_render_adhoc_expression_for_metadata_lookup) and then performing the metadata lookup, ensuring calculated columns resolve properly while preserving the improvements introduced in the original refactor.Additionally:
Mapped[SqlaTable]forward references to use quoted strings (Mapped["SqlaTable"]) inTableColumnandSqlMetric—SqlaTableis defined after both classes so the unquoted form is a forward reference error.tbl, _totbl, _unused_cteto avoid shadowing thelazy_gettexttranslation function (_) imported at module level.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE:
570342908-208dcc04-dfc4-4cdb-91a8-6fb9418b894c.mp4
AFTER:
570343108-8ebd9dd1-a2b6-4cbc-b76b-fd1adbd6cf2e.mp4
TESTING INSTRUCTIONS
Build a chart based on this dataset (Charts → select the virtual table → Bar Chart).
Create a calculated column on the virtual dataset:
gt_or_lt_50CASE WHEN random_value > 50 THEN 'GT 50' ELSE 'LT 50' ENDDrag
event_dateto the x-axis andrandom_valueto metrics. Confirm the bar chart renders.Create an example dashboard and add the chart.
Create a second virtual dataset for the filter:
Add a Value filter to the dashboard:
breakdown_byaggregationOpen the chart and add the following custom SQL to the Dimension field:
Save the chart and return to the dashboard.
categoryfrom the filter — verify the chart updates correctly.gt_or_lt_50from the filter — before this fix this would error; after the fix the chart should update and display the calculated column breakdown correctly.ADDITIONAL INFORMATION
FEATURE_ENABLE_TEMPLATE_PROCESSING: true