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


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx:
##########
@@ -212,6 +217,7 @@ const FilterValue: FC<FilterValueProps> = ({
     const newFormData = getFormData({
       ...filter,
       datasetId,
+      datasourceType,

Review Comment:
   **Suggestion:** `datasourceType` is now part of the query payload, but it is 
not included in the effect dependency list that triggers data refreshes. If the 
datasource type changes while `datasetId` stays the same (the exact collision 
case this PR introduces), the effect can keep using stale form data and skip 
refetching, so filter options can come from the wrong datasource. Add 
`datasourceType` to the effect dependencies so switching datasource kind always 
rebuilds and reloads the filter query. [stale reference]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Native filter options use columns from old datasource.
   - ⚠️ Semantic view filters may query wrong backend dataset.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In the native filter configuration flow, `FiltersConfigForm` computes 
`datasetId` and
   `datasourceType` for each filter (see
   
`superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:11-23`),
   where `datasetId` and `datasourceType` are derived from 
`filterToEdit?.targets?.[0]` /
   `customizationToEdit?.targets?.[0]`.
   
   2. `ColumnSelect` shows that datasets and semantic views can share the same 
numeric ID but
   differ in `datasourceType` (see
   
`superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx:96-101`),
   and explicitly constructs `datasourceKey = \`${datasetId}__${datasourceType 
|| 'table'}\``
   so switching between `'table'` and `'semantic_view'` with the same 
`datasetId` is a real,
   supported scenario.
   
   3. At runtime, `FilterControl` renders `FilterValue` for each native filter 
(see
   
`superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl.tsx:20-34`),
   and `FilterValue` destructures `datasetId` and `datasourceType` from 
`filter.targets[0]`
   (see `FilterValue.tsx` around lines 28-37), then uses both when building 
`newFormData`
   inside the `useEffect` shown in the PR hunk (lines 217-227), passing 
`datasetId` and
   `datasourceType` into `getFormData`.
   
   4. That `useEffect`'s dependency array (shown in `FilterValue.tsx` lines 
193-206) includes
   `datasetId` but not `datasourceType`, even though `datasourceType` 
participates in the
   query payload (line 220). Therefore, when a filter's 
`targets[0].datasourceType` changes
   (e.g., user switches from a physical dataset to a semantic view that reuses 
the same
   `datasetId`, a scenario explicitly called out in `ColumnSelect.tsx:96-101`), 
it is
   possible for all listed dependencies (`datasetId`, `dependencies`, `filter`, 
etc.) to
   remain referentially unchanged while `datasourceType` changes, so this 
effect does not
   rerun and `formData` stays bound to the old datasource kind, causing the 
filter query to
   hit the wrong datasource until some other dependency changes or the 
dashboard reloads.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aa1021de601a43b5845e7bd3b06f25fe&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aa1021de601a43b5845e7bd3b06f25fe&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/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
   **Line:** 220:220
   **Comment:**
        *Stale Reference: `datasourceType` is now part of the query payload, 
but it is not included in the effect dependency list that triggers data 
refreshes. If the datasource type changes while `datasetId` stays the same (the 
exact collision case this PR introduces), the effect can keep using stale form 
data and skip refetching, so filter options can come from the wrong datasource. 
Add `datasourceType` to the effect dependencies so switching datasource kind 
always rebuilds and reloads the filter query.
   
   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%2F40475&comment_hash=1fd135cdd6639502e5c8a75711e440d0e913fa8e180d67492d9d2832db98904f&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40475&comment_hash=1fd135cdd6639502e5c8a75711e440d0e913fa8e180d67492d9d2832db98904f&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