Open
Description
Bug description
In Superset, the "Drill to details by" feature does not apply filters correctly when generating the SQL query. If used without any filters, all raw data is displayed correctly. However, when filters are applied and the feature is used, the generated SQL query does not include the filters, resulting in the display of raw records instead of the filtered records in the drill down.
How to reproduce the bug
-
Create a Virtual Dataset:
SalesDataset: SELECT region, customer_name, sales_usd FROM public.sales WHERE 1 = 1 {% if filter_values('company')|length %} AND company IN {{ filter_values('company')|where_in }} {% endif %}
-
Create a Virtual Dataset for Filter:
CompanyFilterDataSet: SELECT DISTINCT company AS company FROM public.sales
-
Create a Pivot Table Chart:
- DataSet: SalesDataset
- Rows: region
- Column: customer_name
- Metric: count(sales_usd)
-
Create a Dashboard Filter:
- **Source: CompanyFilterDataSet
- **Column: company
-
**Test without Applying Filter:
- **Use the "Drill to details by all" feature.
- **The drill down shows the correct number of records.
-
Apply Filter and Test Again:
- **Apply a filter using the CompanyFilterDataSet.
- **Notice that the values in the chart change according to the filter.
- **Use the "Drill to details by all" feature.
- **The drill down shows the original raw records (without the filter) instead of the filtered records.
Expected Behavior
The generated SQL query for the drill down should include the applied filters, and the drill down should display the filtered records.
Screenshots/recordings
Superset version
4.0.1
Python version
3.11
Node version
18 or greater
Browser
Chrome
Additional context
When creating a dashboard, I performed the following steps:
- Created a dataset
SalesDataset
with a filter condition for company. - Created another dataset CompanyFilterDataSet for filtering companies.
- Built a pivot table chart using SalesDataset, with
region as rows, customer_name as columns, and count(sales_usd)
as the metric. - Added a dashboard filter using
CompanyFilterDataSet
on thecompany
column. - Initially, without applying any filters, the drill down feature shows the correct number of records. However, when a filter is applied, although the chart updates correctly, the drill down shows the original unfiltered records.
Checklist
- I have searched Superset docs and Slack and didn't find a solution to my problem.
- 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.