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


##########
tests/integration_tests/dashboards/api_tests.py:
##########
@@ -91,7 +91,7 @@ class TestDashboardApi(ApiEditorsTestCaseMixin, 
InsertChartMixin, SupersetTestCa
         "description": "desc_changed",
         "position_json": '{"b": "B"}',
         "css": "css_changed",
-        "json_metadata": '{"refresh_frequency": 30, 
"timed_refresh_immune_slices": [], "expanded_slices": {}, "color_scheme": "", 
"label_colors": {}, "shared_label_colors": [], "map_label_colors": {}, 
"color_scheme_domain": [], "cross_filters_enabled": false}',  # noqa: E501
+        "json_metadata": '{"refresh_frequency": 30, 
"timed_refresh_immune_slices": [], "expanded_slices": {}, "expand_all_slices": 
False, "color_scheme": "", "label_colors": {}, "shared_label_colors": [], 
"map_label_colors": {}, "color_scheme_domain": [], "cross_filters_enabled": 
false}',  # noqa: E501

Review Comment:
   **Suggestion:** The new metadata payload embeds a Python boolean literal 
inside a JSON string, which makes the JSON invalid. The API validates 
`json_metadata` as JSON, so requests built from this fixture will fail 
validation (400) instead of reaching the success-path assertions. Use valid 
JSON booleans in the serialized string. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ Dashboard create/update API rejects json_metadata payload in tests.
   ⚠️ Integration tests for dashboard metadata fail before assertions.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In `tests/integration_tests/dashboards/api_tests.py:18-27`, examine
   `TestDashboardApi.dashboard_data`, where the `json_metadata` field is a 
serialized string
   containing `"expand_all_slices": False` (Python-style boolean literal) 
alongside
   `"cross_filters_enabled": false` (valid JSON boolean).
   
   2. Note that dashboard API schemas declare `json_metadata` as a string 
validated by
   `validate_json_metadata` in `superset/dashboards/schemas.py:8-17`, and
   `DashboardPostSchema` / `DashboardPutSchema` wire this validator via 
`json_metadata =
   fields.String(..., validate=validate_json_metadata)` at
   `superset/dashboards/schemas.py:428-431`.
   
   3. When an integration test (or future code) uses `dashboard_data` as the 
payload for
   `POST /api/v1/dashboard` or `PUT /api/v1/dashboard/<id>` (endpoints defined 
in
   `superset/dashboards/api.py:380-399`), the request body includes the invalid
   `json_metadata` string with `expand_all_slices`: False.
   
   4. On request handling, `validate_json_metadata` executes 
`json.loads(value)` (line 12)
   which raises `json.JSONDecodeError` because `False` is not a valid JSON 
literal inside the
   string; this is caught and re-raised as `ValidationError("JSON not valid")` 
(lines 13-17),
   causing the dashboard API to return a 400/422 error and any test using 
`dashboard_data` to
   fail validation before reaching success-path assertions.
   ```
   </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=a566b9b2657343aeb7039b2b8542f8f2&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=a566b9b2657343aeb7039b2b8542f8f2&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:** tests/integration_tests/dashboards/api_tests.py
   **Line:** 94:94
   **Comment:**
        *Api Mismatch: The new metadata payload embeds a Python boolean literal 
inside a JSON string, which makes the JSON invalid. The API validates 
`json_metadata` as JSON, so requests built from this fixture will fail 
validation (400) instead of reaching the success-path assertions. Use valid 
JSON booleans in the serialized string.
   
   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%2F32958&comment_hash=311bb5df37ec56728d9b5203f07373db2d1ce0f47acecb83626b2bd2b21f0650&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=311bb5df37ec56728d9b5203f07373db2d1ce0f47acecb83626b2bd2b21f0650&reaction=dislike'>👎</a>



##########
superset-frontend/spec/fixtures/mockDashboardState.js:
##########
@@ -114,6 +114,6 @@ export const overwriteConfirmMetadata = {
     editors: [],
     viewers: [],
     json_metadata:
-      
'{"timed_refresh_immune_slices":[],"expanded_slices":{},"refresh_frequency":0,"default_filters":"{}","color_scheme":"supersetColors","label_colors":{"0":"#FCC700","1":"#A868B7","15":"#3CCCCB","30":"#A38F79","45":"#8FD3E4","age":"#1FA8C9","Yes,":"#1FA8C9","Female":"#454E7C","Prefer":"#5AC189","No,":"#FF7F44","Male":"#666666","Prefer
 not to say":"#E04355","Ph.D.":"#FCC700","associate\'s 
degree":"#A868B7","bachelor\'s degree":"#3CCCCB","high school diploma or 
equivalent (GED)":"#A38F79","master\'s degree (non-professional)":"#8FD3E4","no 
high school (secondary school)":"#A1A6BD","professional degree (MBA, MD, JD, 
etc.)":"#ACE1C4","some college credit, no degree":"#FEC0A1","some high 
school":"#B2B2B2","trade, technical, or vocational training":"#EFA1AA","No, not 
an ethnic minority":"#1FA8C9","Yes, an ethnic 
minority":"#454E7C","<NULL>":"#5AC189","Yes":"#FF7F44","No":"#666666","last_yr_income":"#E04355","More":"#A1A6BD","Less":"#ACE1C4","I":"#FEC0A1","expected_earn":"#B2B2B2","Yes:
  Willing To":"#EFA1AA","No: Not Willing to":"#FDE380","No 
Answer":"#D3B3DA","In an Office (with Other Developers)":"#9EE5E5","No 
Preference":"#D1C6BC","From 
Home":"#1FA8C9"},"color_scheme_domain":["#1FA8C9","#454E7C","#5AC189","#FF7F44","#666666","#E04355","#FCC700","#A868B7","#3CCCCB","#A38F79","#8FD3E4","#A1A6BD","#ACE1C4","#FEC0A1","#B2B2B2","#EFA1AA","#FDE380","#D3B3DA","#9EE5E5","#D1C6BC"],"shared_label_colors":["Male",
 "Female","<NULL>","Prefer not to say","No Answer","Yes, an ethnic 
minority","No, not an ethnic 
minority","age"],"cross_filters_enabled":false,"filter_scopes":{},"chart_configuration":{},"positions":{}}',
+      
'{"timed_refresh_immune_slices":[],"expanded_slices":{},"expand_all_slices":"false","refresh_frequency":0,"default_filters":"{}","color_scheme":"supersetColors","label_colors":{"0":"#FCC700","1":"#A868B7","15":"#3CCCCB","30":"#A38F79","45":"#8FD3E4","age":"#1FA8C9","Yes,":"#1FA8C9","Female":"#454E7C","Prefer":"#5AC189","No,":"#FF7F44","Male":"#666666","Prefer
 not to say":"#E04355","Ph.D.":"#FCC700","associate\'s 
degree":"#A868B7","bachelor\'s degree":"#3CCCCB","high school diploma or 
equivalent (GED)":"#A38F79","master\'s degree (non-professional)":"#8FD3E4","no 
high school (secondary school)":"#A1A6BD","professional degree (MBA, MD, JD, 
etc.)":"#ACE1C4","some college credit, no degree":"#FEC0A1","some high 
school":"#B2B2B2","trade, technical, or vocational training":"#EFA1AA","No, not 
an ethnic minority":"#1FA8C9","Yes, an ethnic 
minority":"#454E7C","<NULL>":"#5AC189","Yes":"#FF7F44","No":"#666666","last_yr_income":"#E04355","More":"#A1A6BD","Less":"#ACE1C4","I":"#FEC0A1","ex
 pected_earn":"#B2B2B2","Yes: Willing To":"#EFA1AA","No: Not Willing 
to":"#FDE380","No Answer":"#D3B3DA","In an Office (with Other 
Developers)":"#9EE5E5","No Preference":"#D1C6BC","From 
Home":"#1FA8C9"},"color_scheme_domain":["#1FA8C9","#454E7C","#5AC189","#FF7F44","#666666","#E04355","#FCC700","#A868B7","#3CCCCB","#A38F79","#8FD3E4","#A1A6BD","#ACE1C4","#FEC0A1","#B2B2B2","#EFA1AA","#FDE380","#D3B3DA","#9EE5E5","#D1C6BC"],"shared_label_colors":["Male",
 "Female","<NULL>","Prefer not to say","No Answer","Yes, an ethnic 
minority","No, not an ethnic 
minority","age"],"cross_filters_enabled":false,"filter_scopes":{},"chart_configuration":{},"positions":{}}',

Review Comment:
   **Suggestion:** This fixture stores the new expand-all setting as the string 
`"false"` instead of a boolean. In dashboard code paths that rely on truthiness 
(`value || false` and `!!value`), that string is truthy and can flip behavior 
to “expanded” unexpectedly, producing incorrect test state and masking real 
regressions. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ⚠️ DashboardState.expandAllSlices treats "false" string as true.
   ⚠️ Chart description expansion tests may mask regressions.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Inspect the overwrite-confirm fixture at
   `superset-frontend/spec/fixtures/mockDashboardState.js:35-39`, where
   `overwriteConfirmMetadata.data.json_metadata` includes the field
   `expand_all_slices":"false"` encoded as a JSON string rather than a boolean.
   
   2. Parse this JSON string to a metadata object (the same way the 
backend-returned
   `json_metadata` is consumed) so that `metadata.expand_all_slices` equals the 
string
   `"false"` instead of the boolean `false`.
   
   3. Call `hydrateDashboard()` in
   `superset-frontend/src/dashboard/actions/hydrate.ts:360-399`, which builds 
Redux dashboard
   state and sets `expandAllSlices` as `metadata?.expand_all_slices || false` 
(line 378),
   resulting in `expandAllSlices` holding the truthy `"false"` string.
   
   4. Render a chart using
   
`superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:200-215`,
 where
   `isExpanded` is computed as `!!((state.dashboardState as
   JsonObject).expandedSlices?.[props.id] ?? (state.dashboardState as
   JsonObject).expandAllSlices)`; with no per-slice override and 
`expandAllSlices` equal to
   `"false"`, `isExpanded` becomes `true`, so chart descriptions show as 
expanded even though
   metadata conceptually encodes a disabled state, leading 
dashboard-description behavior
   (and any tests using this metadata) to diverge from the intended boolean 
semantics.
   ```
   </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=815bed13f5d84d018b02b366ee1253b3&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=815bed13f5d84d018b02b366ee1253b3&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-frontend/spec/fixtures/mockDashboardState.js
   **Line:** 117:117
   **Comment:**
        *Type Error: This fixture stores the new expand-all setting as the 
string `"false"` instead of a boolean. In dashboard code paths that rely on 
truthiness (`value || false` and `!!value`), that string is truthy and can flip 
behavior to “expanded” unexpectedly, producing incorrect test state and masking 
real regressions.
   
   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%2F32958&comment_hash=7bf64d2076c31aa18b2d8da42a79f799e4438cb1bb3f4247430837de65c2e7b8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=7bf64d2076c31aa18b2d8da42a79f799e4438cb1bb3f4247430837de65c2e7b8&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