You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/07/30 00:54:02 UTC

(superset) branch tdd/issue-35263-drill-jinja-filter-values created (now 75800519e73)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a change to branch tdd/issue-35263-drill-jinja-filter-values
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 75800519e73 test(jinja): pin filter_values() drill-to-detail native-filter fallback for virtual datasets

This branch includes the following new commits:

     new 75800519e73 test(jinja): pin filter_values() drill-to-detail native-filter fallback for virtual datasets

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: test(jinja): pin filter_values() drill-to-detail native-filter fallback for virtual datasets

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch tdd/issue-35263-drill-jinja-filter-values
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 75800519e73d381d7d0b625a2432966ef2806516
Author: Claude Code <no...@anthropic.com>
AuthorDate: Wed Jul 29 17:49:29 2026 -0700

    test(jinja): pin filter_values() drill-to-detail native-filter fallback for virtual datasets
    
    Closes #35263
    
    Regression test for issue #35263, which reports that Drill to
    Detail/Drill by on Jinja-templated datasets returns zero rows even
    though the parent chart shows data for the selected value.
    
    Investigation found the reported gap already closed on master:
    ExtraCache.get_filters()/filter_values() in superset/jinja_context.py
    falls back to reading the native {col, op, val} filter format that
    Drill to Detail/Drill by send (query_obj["filter"]), rather than only
    the adhoc_filters format used by ordinary chart/explore requests. That
    fallback is already unit-tested in isolation
    (tests/unit_tests/jinja_context_test.py), but nothing exercised it
    through a real virtual (Jinja-SQL) dataset end-to-end via
    SqlaTable.get_sqla_query, which is the exact code path the reporter's
    dataset goes through.
    
    This adds that missing end-to-end regression test: a virtual dataset
    whose own SQL calls filter_values() in a WHERE clause, queried with a
    native-format filter (mirroring what a drill request sends), asserting
    the rendered SQL contains the drilled-into value.
    
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 tests/unit_tests/models/helpers_test.py | 53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tests/unit_tests/models/helpers_test.py b/tests/unit_tests/models/helpers_test.py
index 579dd1beb0c..83258bc4d95 100644
--- a/tests/unit_tests/models/helpers_test.py
+++ b/tests/unit_tests/models/helpers_test.py
@@ -2405,6 +2405,59 @@ def test_get_sqla_query_allows_jinja_templated_custom_sql_metric_with_columns(
     assert "{{" not in sql
 
 
+def test_get_sqla_query_virtual_dataset_filter_values_drill_to_detail(
+    database: Database,
+) -> None:
+    """
+    Regression for #35263: a Jinja-templated virtual dataset that calls
+    ``filter_values()`` in its own SQL must see filters sent in the native
+    ``{col, op, val}`` format that Drill to Detail/Drill by use, not just
+    the ``adhoc_filters`` format used by ordinary chart/explore requests.
+    Without this, Jinja-based datasets return zero rows when drilled into,
+    even though the parent chart shows data for the selected value.
+    """
+    from superset.connectors.sqla.models import SqlaTable, TableColumn
+
+    table = SqlaTable(
+        database=database,
+        schema=None,
+        table_name="t",
+        sql=(
+            "SELECT a, b FROM t WHERE 1=1 "
+            "{% if filter_values('b') %} "
+            "AND b IN {{ filter_values('b') | where_in }} "
+            "{% endif %}"
+        ),
+        columns=[
+            TableColumn(column_name="a", type="INTEGER"),
+            TableColumn(column_name="b", type="TEXT"),
+        ],
+    )
+
+    result = table.get_sqla_query(
+        columns=["a", "b"],
+        metrics=[],
+        extras={},
+        filter=[{"col": "b", "op": "IN", "val": ["Alice"]}],
+        granularity=None,
+        is_timeseries=False,
+    )
+    assert result is not None
+
+    with database.get_sqla_engine() as engine:
+        sql = str(
+            result.sqla_query.compile(
+                dialect=engine.dialect,
+                compile_kwargs={"literal_binds": True},
+            )
+        )
+
+    assert "'Alice'" in sql, (
+        "filter_values() should resolve native drill-to-detail-style "
+        f"filters inside a virtual dataset's own SQL. Generated SQL: {sql}"
+    )
+
+
 def test_extras_where_is_parenthesized(
     database: Database,
 ) -> None: