Skip to content

Commit effdcac

Browse files
bmuraykhirusackas
andauthored
fix(reports): capture a failed chart's error panel instead of waiting out the budget (#46085)
Co-authored-by: Evan Rusackas <evan@preset.io>
1 parent c954da8 commit effdcac

2 files changed

Lines changed: 79 additions & 15 deletions

File tree

‎superset-frontend/src/components/Chart/Chart.test.tsx‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,58 @@ test('shows loading spinner for client-side errors without errors array when dat
8888
expect(screen.queryByText(/Some client-side error/)).not.toBeInTheDocument();
8989
});
9090

91+
test('renders a failed query error as the only chart container', () => {
92+
const { container } = render(
93+
<Chart
94+
{...baseProps}
95+
chartStatus="failed"
96+
queriesResponse={[{ message: 'Unknown identifier no_such_column' }]}
97+
/>,
98+
);
99+
100+
const chartContainers = container.querySelectorAll('.chart-container');
101+
expect(chartContainers).toHaveLength(1);
102+
expect(chartContainers[0]).toHaveTextContent(
103+
'Unknown identifier no_such_column',
104+
);
105+
});
106+
107+
test.each([
108+
['null', null],
109+
['empty', []],
110+
])('renders the alert of a failed chart with %s responses', (_, responses) => {
111+
const { container } = render(
112+
<Chart
113+
{...baseProps}
114+
chartStatus="failed"
115+
chartAlert="An error occurred while rendering the visualization"
116+
queriesResponse={responses}
117+
/>,
118+
);
119+
120+
const chartContainers = container.querySelectorAll('.chart-container');
121+
expect(chartContainers).toHaveLength(1);
122+
expect(chartContainers[0]).toHaveTextContent(
123+
'An error occurred while rendering the visualization',
124+
);
125+
});
126+
127+
test('keeps a single chart container while a failed chart waits for its datasource', () => {
128+
const { container } = render(
129+
<Chart
130+
{...baseProps}
131+
chartStatus="failed"
132+
chartAlert="Some client-side error"
133+
datasource={PLACEHOLDER_DATASOURCE}
134+
datasetsStatus={ResourceStatus.Loading}
135+
queriesResponse={[{}]}
136+
/>,
137+
);
138+
139+
expect(screen.getByRole('status')).toBeInTheDocument();
140+
expect(container.querySelectorAll('.chart-container')).toHaveLength(1);
141+
});
142+
91143
test('shows the stop message and a re-run affordance when the query was stopped', () => {
92144
const onQuery = jest.fn();
93145
render(
@@ -180,6 +232,7 @@ test('shows a dataset metadata error and clears it after datasource replacement'
180232
/>,
181233
);
182234
expect(screen.getByText(message)).toBeInTheDocument();
235+
expect(screen.getByText(message).closest('.chart-container')).not.toBeNull();
183236
expect(screen.queryByRole('status')).not.toBeInTheDocument();
184237
rerender(
185238
<Chart

‎superset-frontend/src/components/Chart/Chart.tsx‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ function Chart({
324324
}
325325
}, [triggerQuery, runQuery]);
326326

327+
const isAwaitingDatasource = useCallback(
328+
(queryResponse: ChartErrorType) =>
329+
!queryResponse?.errors?.[0] &&
330+
!queryResponse?.message &&
331+
chartAlert !== undefined &&
332+
chartAlert !== NONEXISTENT_DATASET &&
333+
datasource === PLACEHOLDER_DATASOURCE &&
334+
datasetsStatus !== ResourceStatus.Error,
335+
[chartAlert, datasetsStatus, datasource],
336+
);
337+
327338
const renderErrorMessage = useCallback(
328339
(queryResponse: ChartErrorType) => {
329340
const error = queryResponse?.errors?.[0];
@@ -332,14 +343,7 @@ function Chart({
332343
// if datasource is still loading, don't render JS errors
333344
// but always show backend API errors (structured or message-only)
334345
// so users can see real issues like auth failures
335-
if (
336-
!error &&
337-
!queryResponse?.message &&
338-
chartAlert !== undefined &&
339-
chartAlert !== NONEXISTENT_DATASET &&
340-
datasource === PLACEHOLDER_DATASOURCE &&
341-
datasetsStatus !== ResourceStatus.Error
342-
) {
346+
if (isAwaitingDatasource(queryResponse)) {
343347
return (
344348
<Styles
345349
key={chartId}
@@ -370,9 +374,8 @@ function Chart({
370374
chartId,
371375
chartStackTrace,
372376
dashboardId,
373-
datasetsStatus,
374-
datasource,
375377
height,
378+
isAwaitingDatasource,
376379
],
377380
);
378381

@@ -506,18 +509,26 @@ function Chart({
506509

507510
if (datasource?.metadata_error) {
508511
return (
509-
<ErrorContainer height={height}>
512+
<ErrorContainer className="chart-container" height={height}>
510513
{renderErrorMessage({ message: datasource.metadata_error })}
511514
</ErrorContainer>
512515
);
513516
}
514517

515518
if (chartStatus === 'failed') {
519+
const failedResponses = (
520+
queriesResponse?.length ? queriesResponse : [{}]
521+
) as ChartErrorType[];
516522
return (
517-
<ErrorContainer height={height}>
518-
{queriesResponse?.map(item =>
519-
renderErrorMessage(item as ChartErrorType),
520-
)}
523+
<ErrorContainer
524+
className={
525+
failedResponses.some(item => isAwaitingDatasource(item))
526+
? undefined
527+
: 'chart-container'
528+
}
529+
height={height}
530+
>
531+
{failedResponses.map(item => renderErrorMessage(item))}
521532
</ErrorContainer>
522533
);
523534
}

0 commit comments

Comments
 (0)