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


##########
superset-frontend/src/pages/ChartList/index.tsx:
##########
@@ -500,6 +499,11 @@ function ChartList(props: ChartListProps) {
       },
       {
         Cell: ({ row: { original } }: any) => {
+          // Verify owner or isAdmin
+          const allowEdit: boolean =
+            original.owners.map((o: Owner) => o.id).includes(user.userId) ||
+            isUserAdmin(user);
+

Review Comment:
   **Suggestion:** `owners` is optional in the chart type, but this code calls 
`.map` directly on `original.owners`. If a chart row is returned without 
owners, this throws at runtime and breaks rendering of the actions column. 
Default to an empty array or use optional chaining before mapping. [null 
pointer]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Chart list actions column crashes when owners missing.
   - ⚠️ Users cannot edit or delete affected charts.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Observe the Chart model in `superset-frontend/src/types/Chart.ts:33-47`, 
where
   `owners?: Owner[];` is explicitly declared optional, so a `Chart` instance 
may have
   `owners` as `undefined` rather than an array.
   
   2. In `superset-frontend/src/pages/ChartList/index.tsx`,
   `useListViewResource<Chart>('chart', ...)` (around lines 179-191) fetches 
chart rows as
   `Chart` objects and passes them into the `columns` definition created in the 
`useMemo`
   block starting near the PR hunk that defines the Actions column.
   
   3. When ListView renders the Actions column, it invokes the cell renderer at 
PR hunk lines
   502-506, where `allowEdit` is computed as `original.owners.map((o: Owner) =>
   o.id).includes(user.userId) || isUserAdmin(user);` without providing a 
default for
   `original.owners`, unlike the Owners column above which destructures 
`original: { owners =
   [] }`.
   
   4. For any chart row where the backend omits the `owners` field (leaving 
`original.owners`
   as `undefined` consistent with the optional type in `Chart.ts`), this cell 
renderer
   attempts to call `.map` on `undefined`, throwing a runtime `TypeError: 
Cannot read
   properties of undefined (reading 'map')` and breaking rendering of the 
Actions column (and
   potentially the entire chart list view) for those rows.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fpages%2FChartList%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20504%3A506%0A%2A%2AComment%3A%2A%2A%0A%09%2ANull%20Pointer%3A%20%60owners%60%20is%20optional%20in%20the%20chart%20type%2C%20but%20this%20code%20calls%20%60.map%60%20directly%20on%20%60original.owners%60.%20If%20a%20chart%20row%20is%20returned%20without%20owners%2C%20this%20throws%20at%20runtime%20and%20breaks%20rendering%20of%20the%20actions%20column.%20Default%20to%20an%20empty%20array%20or%20use%20optional%20chaining%20before%20mapping.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20
 
user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fpages%2FChartList%2Findex.tsx%0A%2A%2ALine%3A%2A%2A%20504%3A506%0A%2A%2AComment%3A%2A%2A%0A%09%2ANull%20Pointer%3A%20%60owners%60%20is%20optional%20in%20the%20chart%20type%2C%20but%20this%20code%20calls%20%60.map%60%20directly%20on%20%60original.owners%60.%20If%20a%20chart%20row%20is%20returned%20without%20owners%2C%20this%20throws%20at%20runtime%20and%20breaks%20rendering%20of%20the%20actions%20column.%20Default%20to%20an%20empty%20array%20or%20use%20optional%20chaining%20before%20mapping.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2
 
C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(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/pages/ChartList/index.tsx
   **Line:** 504:506
   **Comment:**
        *Null Pointer: `owners` is optional in the chart type, but this code 
calls `.map` directly on `original.owners`. If a chart row is returned without 
owners, this throws at runtime and breaks rendering of the actions column. 
Default to an empty array or use optional chaining before mapping.
   
   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%2F32995&comment_hash=e3ab40bd0ba0227fac5a87ea7f59b50672bd74193de127ba8a8afd6359468114&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32995&comment_hash=e3ab40bd0ba0227fac5a87ea7f59b50672bd74193de127ba8a8afd6359468114&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