Bug description

Description

Dashboard charts that are powered by Jinja are able to display their data correctly. However, when users try to perform the drill-by action, the result is incorrect.

How to reproduce the bug

  1. By following this guide, create a Jinja-powered dataset with country, status, and product_line columns.
  2. Create a stacked Bar Chart and add it to a dashboard.
  3. Add a filter for the Product Line from the Vehicle Sales dataset.
  4. Ensure that the dashboard shows correct data.
  5. On the stacked Bar Chart, perform a drill to detail by all action.

Expected results

Drill-by results are correct.

Actual results

Drill-by results are incorrect.

Known Workarounds

No workarounds are currently known.

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Comment From: dosubot[bot]

This issue is caused by a disconnect between the context available to Jinja templates during regular chart rendering and what is provided during drill-to-detail actions. When you drill, the frontend sends a new request that often lacks the full dashboard/global context (like dashboard filters or URL params) that your Jinja SQL expects, so the template renders incorrectly or with missing values. This is a known limitation and has been discussed in several issues and code reviews (example, example).

A workaround is to make your Jinja SQL more robust by using if/else blocks to provide default values when filters are missing, so the query always returns results and columns don't disappear. For example:

WITH calculation as (
  SELECT count(*), country
  FROM "Vehicle Sales"
  WHERE 1=1
  {% if filter_values('product_line') %}
    and product_line in {{ filter_values('product_line')|where_in }}
  {% else %}
    and product_line = 'Classic Cars'
  {% endif %}
  GROUP BY country
)
SELECT * FROM calculation

(source)

If your dataset relies on dashboard-level filters or variables, you may need to adjust your Jinja logic to handle cases where those are missing during drill actions.

There have also been recent changes to how Superset syncs dataset columns and processes Jinja templates, which can impact this behavior (PR 30903). Make sure your configuration enables ENABLE_TEMPLATE_PROCESSING and that your feature flags are up to date.

At this time, there is no full workaround for preserving all dashboard context in drill-to-detail requests, but making your Jinja SQL more defensive can help avoid empty or broken results.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

Comment From: Nandu9494

@geido I would like to take this, Please assign to me

Comment From: syedbarimanjan

@msyavuz I would like to work on this can you assign it to me. Thanks

Comment From: msyavuz

@Nandu9494 Can we chat on slack? We have a channel for bounties.

Comment From: syedbarimanjan

@yousoph I followed the guide but couldnt reproduce the issue it is working fine on my end could you provide some more info into it specifically the jinja template.

Here is my jinja template ``` WITH calculation as ( SELECT count(*), country FROM "cleaned_sales_data" WHERE 1=1 {% if filter_values('product_line') %} and product_line in {{ filter_values('product_line')|where_in }} {% else %} and product_line = 'Classic Cars' {% endif %} GROUP BY country ) SELECT * FROM calculation ````

Comment From: syedbarimanjan

@yousoph any update on this?