Skip to content

Comments

fix(alerts): fix error toast when editing report with saved tab selection#38198

Draft
sadpandajoe wants to merge 4 commits intomasterfrom
fix-alert-report-tab-error
Draft

fix(alerts): fix error toast when editing report with saved tab selection#38198
sadpandajoe wants to merge 4 commits intomasterfrom
fix-alert-report-tab-error

Conversation

@sadpandajoe
Copy link
Member

@sadpandajoe sadpandajoe commented Feb 23, 2026

SUMMARY

What happens: Opening the edit modal for a report/alert that has a saved tab selection shows a misleading "There was an error retrieving dashboard tabs" error toast.

When it happens: The dashboard tabs API call succeeds, but the response processing in the .then() handler crashes when:

  1. The selected tab has no scoped native filters — nativeFilters[anchor] is undefined, so .map() throws a TypeError
  2. The dashboard has zero native filters — nativeFilters is an empty object {}, same crash path
  3. all_tabs is null — the in operator throws on a non-object operand

The outer .catch() swallows the TypeError and shows the tabs error toast, even though the API itself returned valid data.

Fix: Add null guards and optional chaining in the tabs useEffect handler (AlertReportModal.tsx):

  • nativeFilters ?? {} — prevents Object.values(undefined) crash
  • nativeFilters?.[anchor] ?? [] — prevents .map() on undefined when anchor key is missing
  • allTabs && / !allTabs || guards — prevents in operator crash on null
  • nativeFilters?.all — prevents crash when native_filters key is omitted entirely
  • Replaced 3 any type annotations with NativeFilterObject

Tests: 7 new regression tests covering all crash paths.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — the error toast no longer appears; no visual changes.

TESTING INSTRUCTIONS

  1. Create a dashboard with tabs and at least one native filter
  2. Create a report targeting that dashboard and select a specific tab
  3. Open the edit modal for the report
  4. Verify no "There was an error retrieving dashboard tabs" error toast appears
  5. Verify tab selection and filter dropdowns work correctly
  6. Also test with a dashboard that has tabs but zero native filters

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

sadpandajoe and others added 3 commits February 19, 2026 22:23
…t robustness

Defend against crash when tabs API response omits native_filters by
defaulting to empty object. Strengthen stale-anchor test to assert
placeholder visibility instead of weak DOM selector. Scope fetchMock
route resets to named routes only, fixing unnamed route leak from
filter-reappears test that caused two downstream test failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add FETCH_CHART_ENDPOINT restore to restoreAnchorMocks for setup/teardown
symmetry. Replace .ant-tree-select and .rc-virtual-list class selectors
with RTL-native queries (queryByTitle, findByRole). Replace i18n-copy-
dependent placeholder assertion with structural title-absence check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Trigger save after stale anchor is processed and inspect the PUT request
body to verify extra.dashboard.anchor is undefined. This directly asserts
the component state through its API boundary rather than checking DOM
elements or i18n-dependent UI copy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Feb 23, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 7f98456
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/699cc6983808310008eea24b
😎 Deploy Preview https://deploy-preview-38198--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in AlertReportModal’s dashboard tabs useEffect when the tabs API returns malformed or incomplete native_filters / all_tabs data, preventing a misleading “retrieving dashboard tabs” toast from being shown when the request itself succeeded.

Changes:

  • Guarded access to native_filters and all_tabs to avoid runtime exceptions in the tabs handler.
  • Improved local typing by replacing several any annotations with NativeFilterObject.
  • Added regression tests covering multiple malformed-payload crash paths and validating toast behavior via a Redux store.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
superset-frontend/src/features/alerts/AlertReportModal.tsx Adds defensive guards around native_filters / all_tabs usage in the tabs-loading effect to prevent crashes on malformed responses.
superset-frontend/src/features/alerts/AlertReportModal.test.tsx Adds regression tests for the new guard behavior, including ensuring the danger toast is only shown on actual request failure.

Comment on lines 894 to 900
await waitFor(() => {
expect(
fetchMock.callHistory.calls().some(c =>
c.url.includes('/dashboard/1/tabs'),
),
).toBe(true);
});
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new tests use fetchMock.callHistory.calls().some(...) to wait for the tabs request, but this file doesn’t clear fetch-mock call history between tests. That means a previous test’s /dashboard/1/tabs call can make this waitFor pass immediately, and the toast assertions can run before the current test’s .then() handler executes (false positives). Clear history at the start of each test (or inside setupAnchorMocks) and/or assert against fetchMock.callHistory.calls(tabsEndpoint) after clearing.

Copilot uses AI. Check for mistakes.
…b-error

# Conflicts:
#	superset-frontend/src/features/alerts/AlertReportModal.test.tsx
@sadpandajoe sadpandajoe changed the title fix(alerts): prevent crash in AlertReportModal tabs handler on malformed API data fix(alerts): fix error toast when editing report with saved tab selection Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant