MDeadman commented on code in PR #38638:
URL: https://github.com/apache/superset/pull/38638#discussion_r2933259113


##########
superset/charts/data/api.py:
##########
@@ -156,6 +180,53 @@ def get_data(  # noqa: C901
         json_body["result_type"] = request.args.get("type", 
ChartDataResultType.FULL)
         json_body["force"] = request.args.get("force")
 
+        # Apply dashboard filter context when filters_dashboard_id is provided
+        dashboard_filter_context: DashboardFilterContext | None = None
+        filters_dashboard_id = request.args.get("filters_dashboard_id", 
type=int)
+        if filters_dashboard_id is not None:
+            try:
+                dashboard_filter_context = get_dashboard_filter_context(
+                    dashboard_id=filters_dashboard_id,
+                    chart_id=pk,
+                )
+            except ValueError as error:
+                return self.response_400(message=str(error))
+            except SupersetSecurityException:
+                return self.response_403()
+
+            if dashboard_filter_context.extra_form_data:
+                efd = dashboard_filter_context.extra_form_data
+                extra_filters = efd.get("filters", [])
+
+                for query in json_body.get("queries", []):
+                    if extra_filters:
+                        existing = query.get("filters", [])
+                        query["filters"] = existing + [
+                            {**f, "isExtra": True} for f in extra_filters
+                        ]
+
+                    extras = query.get("extras", {})
+                    for key in EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS:
+                        if key in efd:
+                            extras[key] = efd[key]
+                    if extras:
+                        query["extras"] = extras
+
+                    for (
+                        src_key,
+                        target_key,
+                    ) in EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS.items():
+                        if src_key in efd:
+                            query[target_key] = efd[src_key]
+
+                    query["extra_form_data"] = efd

Review Comment:
   This also applies to the content in dashboard_filter_context.py. Let me know 
if you think there is a better approach! 



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