codeant-ai-for-open-source[bot] commented on code in PR #36955:
URL: https://github.com/apache/superset/pull/36955#discussion_r2669632649
##########
superset-frontend/src/dashboard/actions/chartCustomizationActions.ts:
##########
@@ -203,10 +204,20 @@ export function saveChartCustomization(
dispatch(onSave(lastModifiedTime));
}
- const { dashboardState } = getState();
- const chartIds = dashboardState.sliceIds || [];
- if (chartIds.length > 0) {
- chartIds.forEach(chartId => {
+ const { sliceEntities } = getState();
Review Comment:
**Suggestion:** Destructuring `sliceEntities` directly from `getState()` and
then accessing `sliceEntities.slices` can throw if `sliceEntities` is undefined
on the current state snapshot; guard the access by defaulting `sliceEntities`
to an empty object before reading `.slices`. [null pointer]
**Severity Level:** Minor ⚠️
```suggestion
const sliceEntities = getState().sliceEntities || {};
```
<details>
<summary><b>Why it matters? ⭐ </b></summary>
The existing code will throw a runtime TypeError if getState().sliceEntities
is undefined because it destructures sliceEntities then immediately reads
sliceEntities.slices. The improved code prevents that by defaulting
sliceEntities to an empty object (or you could use optional chaining: const
slices = getState().sliceEntities?.slices || {};). This is a valid, low-risk
hardening change that avoids a possible crash in some state shapes.
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/actions/chartCustomizationActions.ts
**Line:** 207:207
**Comment:**
*Null Pointer: Destructuring `sliceEntities` directly from `getState()`
and then accessing `sliceEntities.slices` can throw if `sliceEntities` is
undefined on the current state snapshot; guard the access by defaulting
`sliceEntities` to an empty object before reading `.slices`.
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.
```
</details>
##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx:
##########
@@ -161,6 +163,9 @@ const FilterBar: FC<FiltersBarProps> = ({
const chartCustomizationItems = useSelector<RootState, any[]>(
state => state.dashboardInfo.metadata?.chart_customization_config || [],
);
+ const slices = useSelector<RootState, Record<string, Slice>>(
+ state => state.sliceEntities.slices || {},
Review Comment:
**Suggestion:** Selector can throw if `state.sliceEntities` is undefined:
accessing `state.sliceEntities.slices` without optional chaining will cause a
runtime TypeError ("Cannot read property 'slices' of undefined") when
`sliceEntities` is not present in the Redux state. Use optional chaining or a
safer access pattern to avoid the crash. [null pointer]
**Severity Level:** Minor ⚠️
```suggestion
state => state.sliceEntities?.slices || {},
```
<details>
<summary><b>Why it matters? ⭐ </b></summary>
The current selector will throw a runtime TypeError if state.sliceEntities
is ever undefined. Using optional chaining (state.sliceEntities?.slices) is a
small, safe hardening that prevents that crash without changing business logic.
Even if RootState typically guarantees sliceEntities exists, the change is
defensive and low-risk.
</details>
<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/index.tsx
**Line:** 167:167
**Comment:**
*Null Pointer: Selector can throw if `state.sliceEntities` is
undefined: accessing `state.sliceEntities.slices` without optional chaining
will cause a runtime TypeError ("Cannot read property 'slices' of undefined")
when `sliceEntities` is not present in the Redux state. Use optional chaining
or a safer access pattern to avoid the crash.
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.
```
</details>
--
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]