superset icon indicating copy to clipboard operation
superset copied to clipboard

Templates are not being rendered in dataset metrics

Open cbuffevant opened this issue 2 years ago • 1 comments

Templates used in dataset metrics are not being rendered at all when used in charts.

How to reproduce the bug

I was able to replicate the issue running Superset locally followint this instructions https://superset.apache.org/docs/installation/installing-superset-using-docker-compose.

  1. Go to Datasets
  2. Open flights dataset
  3. Create a new metric with this information

name: my_metric label: My Metric SQL: sum(case when '{{ time_grain}}' = 'P1W' then 1 when '{{ time_grain}}' = 'P1D' then -1 else 0 end)

  1. Save the dataset
  2. Go to create a new Chart (for example, Time Series bar chart, v2)
  3. Select flights dataset
  4. Drop My Metric into the Metric section of the chart
  5. Update the chart.
  6. Create a new adhoc metric with the same SQL code than the dataset metric.
  7. Update the chart.

Expected results

Both metrics should display the same information.

Actual results

The dataset metrics is set to 0 while the ad hoc metric has the right values. If you go to check the actual query, you will see that the template {{ time_grain }} is not rendered in the dataset metric case.

Screenshots

image image image image image

Environment

  • browser type and version: Chrome 107.0.5304.110 (Official Build) (x86_64)
  • superset version: I just clone the repo and use non-dev docker-compose script.
  • python version: 3.10.6
  • node.js version: 12.0
  • any feature flags active: ENABLE_TEMPLATE_PROCESSING

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • [X] I have checked the superset logs for python stacktraces and included it here as text if there are any. (No stack trace produced).
  • [X] I have reproduced the issue with at least the latest released version of superset.
  • [X] I have checked the issue tracker for the same issue and I haven't found one similar.

Additional context

I uploaded a video to the Superset Slack channel with the steps to replicated it. https://apache-superset.slack.com/files/U02U4GLFWJC/F04CWRUQ1RR/superset_-_29_november_2022.mp4

cbuffevant avatar Nov 29 '22 16:11 cbuffevant

Assigning to @villebro for the moment, in hopes that he either has some insight here, or can redirect the issue to another contributor who might be able to assist further.

rusackas avatar Nov 30 '22 17:11 rusackas

Repro'd, I'll open a fix asap

villebro avatar Nov 30 '22 18:11 villebro

@cbuffevant @rusackas please check out #22280 .

villebro avatar Nov 30 '22 18:11 villebro