codeant-ai-for-open-source[bot] commented on code in PR #40984:
URL: https://github.com/apache/superset/pull/40984#discussion_r3418377156
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -315,23 +315,40 @@ export default function PluginFilterSelect(props:
PluginFilterSelectProps) {
const uniqueOptions = useMemo(() => {
const allOptions = new Set(data.map(el => el[col]));
- return [...allOptions].map((value: string) => ({
+ const baseOptions = [...allOptions].map((value: string) => ({
label: labelFormatter(value, datatype),
value,
isNewOption: false,
}));
- }, [data, datatype, col, labelFormatter]);
+ if (creatable !== false && filterState.value) {
+ const existing = new Set(allOptions);
+ ensureIsArray(filterState.value)
+ .filter(v => v !== null && v !== undefined && !existing.has(v))
+ .forEach(v => {
+ baseOptions.push({
+ label: String(v),
+ value: String(v),
+ isNewOption: true,
+ });
Review Comment:
**Suggestion:** Converting restored filter values to strings changes the
value type for numeric defaults (`number` → `string`), which can break
equality/matching behavior and produce incorrect filter payload types
downstream. Preserve the original value type when pushing created options so
numeric filters remain numeric. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Restored defaults missing from data change type to string.
- ⚠️ Mixed numeric and string types in filter payloads.
- ⚠️ Downstream consumers may mis-handle stringified numeric filters.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. `PluginFilterSelect` builds its option list in the `uniqueOptions`
`useMemo` at
`SelectFilterPlugin.tsx:117-78`, starting from `data.map(el => el[col])` and
mapping each
value to `{ label: labelFormatter(value, datatype), value, isNewOption:
false }`, so
existing options preserve the underlying value type (number, string, etc.).
2. When `filterState.value` contains entries not present in the current
`data` set and
`creatable !== false`, the block at `SelectFilterPlugin.tsx:323-335` runs:
it iterates
`ensureIsArray(filterState.value).filter(v => v !== null && v !== undefined
&&
!existing.has(v))` and for each such `v` executes `baseOptions.push({ label:
String(v),
value: String(v), isNewOption: true });` (lines 328-332), explicitly
coercing the stored
value to a string.
3. For numeric filters where `filterState.value` holds numeric defaults or
previously-selected numeric values that are no longer present in `data`
(e.g., default ID
`10107` for a column whose current result set omits that ID), those values
enter this path
as `number` but are turned into `string` in the created options, while other
options for
the same column still use numeric `value` types.
4. When the user interacts with the select, `AsyncSelect` maps chosen
options back to raw
values via `mapValues` (`Select utils.tsx:196-207`), so selections
originating from these
created options are returned as strings, and `updateDataMask` in
`SelectFilterPlugin.tsx:97-125` passes these stringified values into
`getSelectExtraFormData` (`filters/utils.ts:50-88`), which forwards them
unchanged into
`extraFormData.filters[].val`.
5. This path means that for values originally represented as numbers in
`filterState.value`, the restored-and-created options now emit string
payloads while other
options emit numbers, leading to type drift in the filter payload and
potential mismatches
for downstream consumers that distinguish numeric versus string filter
values.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1ddb9984618648d2887b199edc6fddb7&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=1ddb9984618648d2887b199edc6fddb7&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/src/filters/components/Select/SelectFilterPlugin.tsx
**Line:** 328:332
**Comment:**
*Type Error: Converting restored filter values to strings changes the
value type for numeric defaults (`number` → `string`), which can break
equality/matching behavior and produce incorrect filter payload types
downstream. Preserve the original value type when pushing created options so
numeric filters remain numeric.
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%2F40984&comment_hash=411c8d9713dab0e9f0e412d5447beadffc32d6244b4c3843b9d81b440309a715&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40984&comment_hash=411c8d9713dab0e9f0e412d5447beadffc32d6244b4c3843b9d81b440309a715&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]