betodealmeida commented on code in PR #41131:
URL: https://github.com/apache/superset/pull/41131#discussion_r3430253152


##########
tests/unit_tests/charts/test_chart_data_api.py:
##########
@@ -73,6 +78,36 @@ def 
test_get_data_sets_g_form_data_without_dashboard_filter() -> None:
         assert g.form_data["queries"][0]["columns"] == ["col1"]
 
 
+def test_apply_dashboard_filter_context_does_not_duplicate_filters() -> None:
+    """
+    Regression test for the ``filters_dashboard_id`` parameter.
+
+    A dashboard's filters must not be present in both query["filters"] and
+    query["extra_form_data"]["filters"]. Previously the same filter existed in 
both,
+    so Jinja's filter_values() read each value twice and produced SQL such as
+    ``country in ('USA', 'USA')``.
+    """
+    query_context_json: dict[str, Any] = {
+        "datasource": {"id": 1, "type": "table"},
+        "queries": [{"filters": [{"col": "year", "op": "IN", "val": [2004]}]}],
+    }
+    extra_form_data = {"filters": [{"col": "country", "op": "IN", "val": 
["USA"]}]}
+
+    apply_dashboard_filter_context(query_context_json, extra_form_data)
+
+    query = query_context_json["queries"][0]
+    assert query["filters"] == [
+        {"col": "year", "op": "IN", "val": [2004]},
+        {"col": "country", "op": "IN", "val": ["USA"], "isExtra": True},
+    ]
+    assert "filters" not in query["extra_form_data"]
+
+    # filter_values() therefore returns the dashboard value exactly once.
+    with current_app.test_request_context("/api/v1/chart/1/data/"):
+        g.form_data = query_context_json
+        assert ExtraCache().filter_values("country") == ["USA"]

Review Comment:
   You should be able to use the `app` fixture here instead.



-- 
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