daviddallakyan2005 opened a new pull request, #43218:
URL: https://github.com/apache/superset/pull/43218

   ### SUMMARY
   
   The Histogram chart throws `TypeError: Cannot convert undefined or null to 
object` and fails to render whenever its query comes back with no rows.
   
   `transformProps` reads the bin labels straight off the first datum:
   
   ```ts
   const xAxisData: string[] = Object.keys(data[0])
   ```
   
   That datum does not always exist. The histogram post-processor drops NULLs 
in the target column and returns the empty frame as-is:
   
   ```python
   # superset/utils/pandas_postprocessing/histogram.py
   df = df.dropna(subset=[column])
   if df.empty:
       return df
   ```
   
   So an all-NULL numeric column, or a filter that matches nothing, sends 
`data: []` to the frontend and `Object.keys(undefined)` throws.
   
   The fix is the guard the sibling Radar plugin already uses for the identical 
lookup (`src/Radar/transformProps.ts`):
   
   ```ts
   const globalMax = findGlobalMax(data, Object.keys(data[0] || {}));
   ```
   
   With `data` empty everything downstream already degrades correctly — 
`data.map(...)` yields no series, the legend list is empty, and the tooltip 
formatter is never called — so the chart renders as an empty plot instead of 
crashing.
   
   Also adds `test/Histogram/transformProps.test.ts`. This plugin had a 
`buildQuery` test but no `transformProps` coverage at all.
   
   ### TESTING INSTRUCTIONS
   
   Automated:
   
   ```bash
   cd superset-frontend
   npm run test -- plugins/plugin-chart-echarts/test/Histogram   # 5 passed
   npm run test -- plugins/plugin-chart-echarts                  # 85 suites, 
895 passed
   ```
   
   Reverting the one-line change makes the new test fail with the reported 
error:
   
   ```
   ● renders an empty chart when the query returns no rows
     TypeError: Cannot convert undefined or null to object
     at keys 
(plugins/plugin-chart-echarts/src/Histogram/transformProps.ts:83:38)
   ```
   
   Manually:
   
   1. Create a Histogram chart on any dataset with a numeric column.
   2. Add a filter that matches no rows (or point it at a numeric column whose 
values are all NULL).
   3. Before: the chart area shows "Unexpected error". After: it renders as an 
empty chart.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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