codeant-ai-for-open-source[bot] commented on code in PR #41133:
URL: https://github.com/apache/superset/pull/41133#discussion_r3486016686
##########
superset/charts/data/dashboard_filter_context.py:
##########
@@ -199,6 +199,31 @@ def _extract_filter_extra_form_data(
return None, DashboardFilterStatus.NOT_APPLIED
+def _resolve_filter_extra_form_data(
+ filter_config: dict[str, Any],
+ active_data_mask: dict[str, Any] | None,
+) -> tuple[dict[str, Any] | None, DashboardFilterStatus]:
+ """
+ Resolve a filter's extra_form_data and status, preferring an active value
+ from ``active_data_mask`` over the filter's saved default.
+
+ When ``active_data_mask`` provides an entry for this filter, its
+ ``extraFormData`` is authoritative: a non-empty value is APPLIED, while an
+ empty value means the user explicitly cleared the filter (NOT_APPLIED, with
+ no fallback to the saved default). When no active entry exists, fall back
to
+ the saved-default behavior in ``_extract_filter_extra_form_data``.
+
+ Returns (extra_form_data, status).
+ """
+ flt_id = filter_config.get("id", "")
+ if active_data_mask is not None and flt_id in active_data_mask:
+ active_efd = (active_data_mask[flt_id] or {}).get("extraFormData") or
{}
+ if active_efd:
+ return active_efd, DashboardFilterStatus.APPLIED
+ return None, DashboardFilterStatus.NOT_APPLIED
Review Comment:
**Suggestion:** The active filter payload is used without validating that
`extraFormData` is actually a dictionary. If a client sends a non-dict value
(for example a list/string), this function returns it as applied data and
downstream merge code will call `.get(...)` on the wrong type, causing chart
export processing to fail and charts to be skipped. Guard the type here (or
reject invalid payloads) before returning `APPLIED`. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Excel export skips charts with malformed active filter payload.
- ⚠️ Dashboard export endpoint accepts invalid extraFormData silently.
- ⚠️ Users receive incomplete workbooks without clear validation error.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Trigger the Excel export endpoint `POST
/api/v1/dashboard/<pk>/export_xlsx/`,
implemented by `DashboardRestApi.export_xlsx` in
`superset/dashboards/api.py:1397-1478`,
sending a JSON body whose `active_data_mask` passes schema validation but
has a non-dict
`extraFormData`, for example:
{
"active_data_mask": {
"filter_1": {
"extraFormData": ["not-a-dict"]
}
}
}
This shape is accepted because
`DashboardExportXlsxPostSchema.active_data_mask` in
`superset/dashboards/schemas.py:638-645` declares `values=fields.Dict()`
but does not
validate the type of the nested `extraFormData` value.
2. The view `export_xlsx` enqueues the Celery task `export_dashboard_excel`
with
`active_data_mask=payload.get("active_data_mask", {})` as shown in
`superset/dashboards/api.py:1470-1478`. The task signature
`export_dashboard_excel(...,
active_data_mask: dict[str, Any], job_id: str)` in
`superset/tasks/export_dashboard_excel.py:49-55` receives this unmodified
dictionary.
3. Inside the task, `_build_workbook` iterates charts and calls
`_write_chart_sheets(writer, chart, dashboard.id, active_data_mask)` as in
`superset/tasks/export_dashboard_excel.py:114-120`. `_write_chart_sheets`
then calls
`get_dashboard_filter_context(dashboard_id=dashboard_id, chart_id=chart.id,
active_data_mask=active_data_mask)` at
`superset/tasks/export_dashboard_excel.py:84-88`.
In `get_dashboard_filter_context`
(`superset/charts/data/dashboard_filter_context.py:269-282`), for each
in-scope filter
`flt`, `_resolve_filter_extra_form_data(flt, active_data_mask)` is invoked
at line 66
(file lines 55-80 in the second chunk we read).
4. `_resolve_filter_extra_form_data` in
`superset/charts/data/dashboard_filter_context.py:218-224` computes:
- `flt_id = filter_config.get("id", "")`
- `active_efd = (active_data_mask[flt_id] or {}).get("extraFormData") or
{}`
Because `active_data_mask["filter_1"]` is a dict and `extraFormData` is
the list
`["not-a-dict"]`, `active_efd` becomes that list (it is truthy, so the
`or {}` fallback
is not used). The function returns `(active_efd,
DashboardFilterStatus.APPLIED)` at
lines 221-222. Back in `get_dashboard_filter_context`, `extra_form_data`
is thus a
list, and it is passed into
`_merge_extra_form_data(context.extra_form_data,
extra_form_data)` at
`superset/charts/data/dashboard_filter_context.py:68-71`.
5. `_merge_extra_form_data` in
`superset/charts/data/dashboard_filter_context.py:120-167`
expects both `base` and `new` to be dictionaries. It immediately calls
`new.get(key, [])`
for multiple keys (lines 137-140) and later `new.get("custom_form_data")`
(lines 145-147).
Since `new` is actually the list `["not-a-dict"]`, Python raises
`AttributeError: 'list'
object has no attribute 'get'`. This exception bubbles out of
`get_dashboard_filter_context` into `_write_chart_sheets`, where
`_build_workbook` catches
it in the broad `except Exception` block at
`superset/tasks/export_dashboard_excel.py:9-15`, logs `"Skipping chart %s in
dashboard
export %s"`, and appends the chart label to `skipped`. The export job
completes, but the
affected chart’s data is omitted from the generated workbook and only listed
as skipped in
the success email.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d5ff39148f0d4876ad8611d8e93184ed&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d5ff39148f0d4876ad8611d8e93184ed&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/charts/data/dashboard_filter_context.py
**Line:** 219:223
**Comment:**
*Type Error: The active filter payload is used without validating that
`extraFormData` is actually a dictionary. If a client sends a non-dict value
(for example a list/string), this function returns it as applied data and
downstream merge code will call `.get(...)` on the wrong type, causing chart
export processing to fail and charts to be skipped. Guard the type here (or
reject invalid payloads) before returning `APPLIED`.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=388da0723e55318916b9a571fe1ad9ff51c77a32eed2af16c60e3bb44282a1cc&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=388da0723e55318916b9a571fe1ad9ff51c77a32eed2af16c60e3bb44282a1cc&reaction=dislike'>👎</a>
--
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]