codeant-ai-for-open-source[bot] commented on code in PR #41133:
URL: https://github.com/apache/superset/pull/41133#discussion_r3574650970


##########
superset/dashboards/schemas.py:
##########
@@ -628,3 +628,30 @@ class CacheScreenshotSchema(Schema):
         fields.List(fields.Str(), validate=lambda x: len(x) == 2), 
required=False
     )
     permalinkKey = fields.Str(required=False)  # noqa: N815
+
+
+class DashboardExportXlsxPostSchema(Schema):
+    active_data_mask = fields.Dict(
+        keys=fields.Str(),
+        values=fields.Dict(),
+        load_default=dict,
+        metadata={
+            "description": "Live dashboard filter state keyed by native filter 
id, "
+            "each carrying an extraFormData object."
+        },
+    )

Review Comment:
   **Suggestion:** `active_data_mask` currently accepts any arbitrary inner 
dict shape, but downstream filter-merging code assumes each entry has a 
dict-like `extraFormData`. If a client sends a non-dict `extraFormData` (for 
example a string or list), the export task hits runtime attribute errors while 
building chart filter context and silently skips charts. Tighten this schema to 
validate the nested structure (especially `extraFormData` as an object/dict) so 
malformed payloads fail fast with a 400 instead of producing broken exports. 
[type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Dashboard export_xlsx endpoint produces incomplete Excel workbooks.
   - ⚠️ Malformed active_data_mask payloads skip charts instead of 400.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Call the dashboard Excel export API `POST 
/api/v1/dashboard/<pk>/export_xlsx/`
   implemented in `superset/dashboards/api.py:1602-109`, with JSON body 
containing
   `active_data_mask` where a filter id key (matching a native filter) maps to 
an object
   whose `"extraFormData"` field is a non-dict, e.g. a string or list.
   
   2. The request body is deserialized via 
`DashboardExportXlsxPostSchema().load(...)` in
   `superset/dashboards/api.py:1649-1651`; the current schema for 
`active_data_mask` at
   `superset/dashboards/schemas.py:633-642` only requires each value to be a 
dict, and does
   not enforce that `"extraFormData"` itself is a dict, so this malformed 
payload passes
   validation and does not raise `ValidationError`.
   
   3. The API enqueues the Celery task by calling 
`export_dashboard_excel.apply_async(...)`
   in `superset/dashboards/api.py:91-103`, passing the unchecked 
`active_data_mask` through
   to the task (`superset/tasks/export_dashboard_excel.py:177-183`).
   
   4. When the task runs, `_build_workbook()` in
   `superset/tasks/export_dashboard_excel.py:91-152` calls
   `get_dashboard_filter_context(dashboard_id, chart.id, 
active_data_mask=active_data_mask)`
   (`superset/tasks/export_dashboard_excel.py:151-154`), which reaches
   `_resolve_filter_extra_form_data()` in
   `superset/charts/data/dashboard_filter_context.py:202-224`. There, 
`active_efd =
   (active_data_mask[flt_id] or {}).get("extraFormData") or {}` at `line 220` 
assumes the
   inner value is dict-like; with a non-dict `"extraFormData"`, `active_efd` 
becomes a
   non-dict (e.g. string), and subsequent use as a mapping (e.g.
   `extra_form_data.pop("filters", [])` in `apply_dashboard_filter_context()` at
   `superset/charts/data/dashboard_filter_context.py:358`) raises an 
AttributeError, causing
   the chart export to fail and be recorded as `email.ERROR_GENERAL` in 
`_build_workbook()`
   at `superset/tasks/export_dashboard_excel.py:137-142`, silently skipping 
that chart
   instead of returning a 400 to the client.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1078b7beb3f84e9bb8983062707d5ebe&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1078b7beb3f84e9bb8983062707d5ebe&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/dashboards/schemas.py
   **Line:** 634:642
   **Comment:**
        *Type Error: `active_data_mask` currently accepts any arbitrary inner 
dict shape, but downstream filter-merging code assumes each entry has a 
dict-like `extraFormData`. If a client sends a non-dict `extraFormData` (for 
example a string or list), the export task hits runtime attribute errors while 
building chart filter context and silently skips charts. Tighten this schema to 
validate the nested structure (especially `extraFormData` as an object/dict) so 
malformed payloads fail fast with a 400 instead of producing broken exports.
   
   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=3069d905ef48c67e1d5b4230b9f55fde7d36374c36cb3844aa8838b12c933af5&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=3069d905ef48c67e1d5b4230b9f55fde7d36374c36cb3844aa8838b12c933af5&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]

Reply via email to