rusackas commented on code in PR #43025:
URL: https://github.com/apache/superset/pull/43025#discussion_r3771601504


##########
tests/unit_tests/views/test_utils.py:
##########
@@ -51,3 +57,77 @@ def test_get_form_data_handles_non_dict_json_body() -> None:
 
     assert form_data == {}
     assert slc is None
+
+
+def test_get_dashboard_extra_filters_includes_native_filter_defaults(
+    session: Session,
+) -> None:
+    """
+    get_dashboard_extra_filters must surface native filter defaults, not just
+    the legacy Filter Box ``default_filters``/``filter_scopes`` metadata.
+
+    Reported in apache/superset#43024 (originally raised in discussion #42382):
+    ``ChartWarmUpCacheCommand`` relies on this function to reconstruct a
+    dashboard's applied filters for cache warming. Because it only reads the
+    legacy fields, warming a
+    dashboard that uses native filters (the standard mechanism today, not the
+    deprecated Filter Box) silently drops every native filter's default
+    value, so the warmed cache key never matches what the browser actually
+    requests and warm_up_cache is effectively a no-op for such dashboards.
+
+    A working native-filter extractor already exists and is wired into the
+    real ``/api/v1/chart/data`` endpoint (see
+    
``superset.charts.data.dashboard_filter_context.get_dashboard_filter_context``)
+    -- this function just isn't using it.
+    """
+    Dashboard.metadata.create_all(session.get_bind())
+
+    dataset = SqlaTable(
+        table_name="extra_filters_table",
+        database=Database(database_name="extra_filters_db", 
sqlalchemy_uri="sqlite://"),
+    )
+    db.session.add(dataset)
+    db.session.flush()
+
+    chart = Slice(
+        slice_name="chart_with_native_filter",
+        datasource_id=dataset.id,
+        datasource_type="table",
+    )
+
+    native_filter_configuration = [
+        {
+            "id": "NATIVE_FILTER-1",
+            "name": "Region filter",
+            "type": "NATIVE_FILTER",
+            "scope": {"rootPath": ["ROOT_ID"], "excluded": []},
+            "targets": [{"column": {"name": "region"}}],
+            "defaultDataMask": {
+                "extraFormData": {
+                    "filters": [{"col": "region", "op": "IN", "val": ["APAC"]}]
+                },
+                "filterState": {"value": ["APAC"]},
+            },
+            "controlValues": {},
+        }
+    ]
+    dashboard = Dashboard(
+        dashboard_title="native_filter_dash",
+        slices=[chart],
+        published=True,
+        json_metadata=json.dumps(
+            {"native_filter_configuration": native_filter_configuration}
+        ),
+        position_json="{}",
+    )
+    db.session.add_all([chart, dashboard])
+    db.session.flush()
+
+    extra_filters = get_dashboard_extra_filters(chart.id, dashboard.id)
+
+    assert extra_filters, (

Review Comment:
   Fair catch — tightened the assertion to check for the exact `{"col": 
"region", "op": "IN", "val": ["APAC"]}` predicate instead of just 
non-emptiness, so a fix that returns a placeholder non-empty value still fails.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to