peterhuson opened a new issue, #43347:
URL: https://github.com/apache/superset/issues/43347

   ### Bug description
   
   In the native-filter config modal, the **Filter has default value** Select 
cannot keep a value that is not already in the first ~1000 loaded options.
   
   Two visible symptoms, one frontend root cause. No database involvement.
   
   1. **Paste** a value (or comma-separated list) that is not in the loaded 
page → tags appear briefly, then the field resets to empty.
   2. **Type** a value that is not in the loaded page → a created option 
appears, then is pruned as soon as the internal selection is reset.
   
   Selecting a value that *is* in the first 1000 rows works.
   
   This is **not** a duplicate of #32645 / #41136. That fix 
(`allowNewOptionsOnPaste`) is for the **dashboard filter bar** paste path when 
`searchAllOptions` is on. This bug is in the **filter-config default-value 
picker**, driven by `DefaultValue.tsx` rebuilding `filterState` as a new object 
every render, plus `Select.tsx` resetting internal state from the `value` prop 
by reference. Still present on 6.1.0 and current `master`. #41136 is also not 
in 6.1.0.
   
   ### How to reproduce
   
   1. Create a dashboard with a Value / Select native filter on a column with 
**> 1000 distinct values**.
   2. Enable **Can select multiple values**.
   3. Check **Filter has default value**.
   4. In the default-value Select:
      - Paste a known-good value that sorts **outside** the first 1000 loaded 
rows (or a comma-separated list containing one).
      - Or type that same value and try to commit it as a created option.
   5. Observe: pasted tags flash then disappear; typed created options do not 
stick.
   
   ### Expected
   
   - Pasted / typed values that exist in the dataset (or that the Select is 
allowed to create) stay selected in the default-value field and are saved on 
the filter.
   - Values already in the loaded page continue to work.
   
   ### Actual
   
   - Paste: local selection is set (flash) → form/`filterState` round-trip → 
re-render → internal selection reset to empty.
   - Typing: created `isNewOption` is pruned the moment it is no longer in 
`selectValue`, which the reset just cleared.
   
   ### Root cause
   
   Three pieces in 6.1.0 combine. Nothing in this path hits the database.
   
   **1. `DefaultValue.tsx` builds a new `filterState` object every render**
   
   
https://github.com/apache/superset/blob/6.1.0/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DefaultValue.tsx#L79-L83
   
       filterState={{
         ...formFilter?.defaultDataMask?.filterState,
         validateMessage: isMissingRequiredValue && t('Value is required'),
         validateStatus: isMissingRequiredValue && 'error',
       }}
   
   **2. The plugin passes that through as the Select `value` prop**
   
   
https://github.com/apache/superset/blob/6.1.0/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx#L513
   
       value={multiSelect ? filterState.value || [] : filterState.value}
   
   `uniqueOptions` is built only from the loaded `data` page (~1000 rows):
   
   
https://github.com/apache/superset/blob/6.1.0/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx#L295-L300
   
   **3. `Select.tsx` resets internal selection from `value` by reference, then 
prunes created options**
   
   
https://github.com/apache/superset/blob/6.1.0/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx#L578-L580
   
       useEffect(() => {
         setSelectValue(value);
       }, [value]);
   
   
https://github.com/apache/superset/blob/6.1.0/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx#L405-L406
   
       const cleanSelectOptions = ensureIsArray(fullSelectOptions).filter(
         opt => !opt.isNewOption || hasOption(opt.value, selectValue),
       );
   
   Sequence:
   
   1. Paste/type sets `selectValue` locally (the flash).
   2. Form round-trip re-renders `DefaultValue` with a **new** `filterState` 
object.
   3. The `value` effect fires because the reference changed.
   4. `setSelectValue` overwrites the internal selection with whatever survived 
the form — usually nothing, because `uniqueOptions` only has the 1000-row page.
   5. On the next search, `cleanSelectOptions` drops the created option because 
it is no longer in `selectValue`.
   
   Same root cause, two symptoms.
   
   ### Suggested direction (not a patch)
   
   - Stabilize `filterState` in `DefaultValue.tsx` (`useMemo`, or pass the 
existing object when only validate fields change).
   - In `Select.tsx`, only call `setSelectValue(value)` when the value is 
**deeply** different, not on every new array/object reference.
   - Keep created / pasted options in `uniqueOptions` (or in the Select's 
option list) across that form round-trip so they are not dropped just because 
they were not in the first 1000 rows.
   
   ### Related (not duplicates)
   
   - #32645 / #41136 — dashboard filter-bar paste when `searchAllOptions` is on 
(`allowNewOptionsOnPaste`). Different surface, different cause, not in 6.1.0.
   - #31886 — default-value dropdown z-index.
   - #17950 — default not applied on the dashboard after save (2022, already 
fixed).
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   6.1.0
   
   ### Python version
   
   3.11
   
   ### Node version
   
   16
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [ ] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


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