bito-code-review[bot] commented on code in PR #40470:
URL: https://github.com/apache/superset/pull/40470#discussion_r3343746279


##########
superset-frontend/src/dataMask/reducer.ts:
##########
@@ -109,10 +109,50 @@ function fillNativeFilters(
 ) {
   filterConfig.forEach((filter: Filter) => {
     const dataMask = initialDataMask || {};
+    const loaded = dataMask[filter.id];
+
+    // The shallow spread of `loaded` would override `filter.defaultDataMask`
+    // even when the loaded mask is incomplete (e.g. a permalink captured
+    // mid-initialization), wiping out a valid default. For REQUIRED filters
+    // with a default, fall back to the default when the loaded mask carries
+    // no real value OR is missing the extraFormData needed to filter charts.
+    // Non-required filters keep current behavior so a user's explicit clear
+    // isn't undone.
+    const isRequired = !!filter.controlValues?.enableEmptyFilter;
+    const loadedValue = loaded?.filterState?.value;
+    const loadedHasValue =
+      loadedValue !== undefined &&
+      loadedValue !== null &&
+      !(
+        // Treat all-null arrays (range filters use [null, null] as their
+        // canonical cleared value) and empty arrays as "no value".
+        (Array.isArray(loadedValue) && loadedValue.every(v => v === null))

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>CWE-252: Empty Array No-Value Check Removed</b></div>
   <div id="fix">
   
   The change removes the `loadedValue.length === 0` check that treats empty 
arrays as "no value". Range filters and required filters with no selection 
(empty array) would now incorrectly be treated as having a value, breaking the 
shouldRestoreDefault fallback logic for required filters. (See also: 
[CWE-252](https://cwe.mitre.org/data/definitions/252.html))
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    --- a/superset-frontend/src/dataMask/reducer.ts
    +++ b/superset-frontend/src/dataMask/reducer.ts
    @@ -126,7 +126,7 @@ function fillNativeFilters(
           !(
             // Treat all-null arrays (range filters use [null, null] as their
             // canonical cleared value) and empty arrays as "no value".
    -        (Array.isArray(loadedValue) && loadedValue.every(v => v === null))
    +        (loadedValue.length === 0 || (Array.isArray(loadedValue) && 
loadedValue.every(v => v === null)))
           );
         const loadedHasExtraFormData =
           !!loaded?.extraFormData && Object.keys(loaded.extraFormData).length 
> 0;
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #f59dee</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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