Repository navigation
feat(dataset): warn about dependent charts and dashboards before purging an archived dataset - #43724
Conversation
Code Review Agent Run #09ae2eActionable Suggestions - 0Additional Suggestions - 8
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The pull request introduces a mechanism to prevent XSS or injection vulnerabilities by ensuring that exception text is properly handled and that destructive actions (like purging an archived dataset) are gated by a confirmed impact token. The changes include updates to the superset-frontend/packages/superset-ui-core/src/components/DeleteModal/index.tsx |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #43724 +/- ##
========================================
Coverage 79.24% 79.25%
========================================
Files 2888 2890 +2
Lines 166446 166719 +273
Branches 38529 38605 +76
========================================
+ Hits 131908 132140 +232
- Misses 32045 32081 +36
- Partials 2493 2498 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… modal Follow-ups from CI and the first review round on the purge warning: - Add the missing OpenAPI operation block to GET /<uuid>/purge-impact; the generated spec had an operation without `responses`, failing test_open_api_spec on every integration lane. - A purge that succeeds after the user closed the modal mid-request now still shows the success toast and refreshes the list; only the modal state remains gated on the request generation. - Impact entries only render as links for server-issued application paths; absolute and scheme-relative URLs render as plain text. Both behaviour fixes have tests that fail against the previous code. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Follow-up pushed as 25781a0:
Comment generated by Claude (AI) on behalf of @mikebridge. |
aminghadersohi
left a comment
There was a problem hiding this comment.
Reviewed at 25781a051a. This is a genuinely careful piece of work on an irreversible operation — the two-phase confirm, the fail-closed preview, and the re-check inside the row lock are the right shape, and the access-redaction design is better than I expected going in. Comments below, heaviest first. One substantive finding, one alert triage, and a few notes; the rest is me confirming things are clean so that's on the record.
1. Impact can under-report: dashboards linked only through native filters
collect_dataset_purge_impact finds dashboards by joining Dashboard → dashboard_slices → Slice and filtering on the slice's datasource (purge_impact.py:93-99). That finds every dashboard that contains a chart built on the dataset. It does not find a dashboard whose only reference to the dataset is a native filter target, because such a dashboard has no dashboard_slices row for it.
That linkage is real and load-bearing elsewhere in this repo:
superset/models/dashboard.py:477— export resolvesnative_filter_configuration[].targets[].datasetIdthroughDatasourceDAO.get_datasource(DatasourceType.TABLE, id_), i.e. straight to aSqlaTable.superset/tasks/native_filter_cache.py:58— the filter cache warms datasets read fromtarget.get("datasetId").superset/migrations/shared/native_filters.py:114,131— the legacyfilter_box→ native-filter migration wrotetargets: [{"datasetId": filter_box.datasource_id}]. Long-lived deployments have exactly this shape today, and in that migration path the filter's dataset need not match any chart on the dashboard.
Consequence: the modal renders "No affected dashboards." (ArchivedDatasetPurgeModal.tsx:106), the user types DELETE, and a dashboard filter silently breaks with no recovery. For an irreversible purge, under-reporting is the direction that costs data; over-reporting is only noise.
Two things keep this off the "blocking" line for me:
- The scoping choice is pre-existing and consistent —
DatasetDAO.get_related_objects(superset/daos/dataset.py:145-165) has the same shape. This PR did not introduce it. docs/docs/using-superset/recently-archived.mdxis precisely worded: "which dashboards contain those charts." That is accurate to the code.
But the docs and the UI disagree in tone. "No affected dashboards." reads as an absolute statement about the dataset, and it is now the last thing a user sees before an unrecoverable action. Either widen the query to union in native_filter_configuration dataset targets, or soften the modal copy to match the docs' narrower claim (e.g. "No dashboards contain affected charts."). The copy change is cheap and closes the honesty gap immediately; the query change is the real fix. Your call which belongs in this PR.
I'd also note Slice.datasource_type == "table" (purge_impact.py:80,98) is correct — I checked, DatasourceDAO.sources maps only TABLE → SqlaTable (superset/daos/datasource.py:50-55), and the model's own relationship uses the same predicate (superset/models/slice.py:167). Not a gap.
2. CodeQL alert 2594 — I believe this is a false positive; here is the reasoning to dismiss it with
Not repeating the bot thread, just triaging it, since it's the only unresolved thread and mergeStateStatus is BLOCKED.
The sink is <a href={item.url}>{item.name}</a> (ArchivedDatasetPurgeModal.tsx:65). The "exception text" the query is tracking is real — it enters at index.tsx:384-396, where the 409 body is pulled out of a caught error via getClientErrorObject(error) and parsedError.impact is fed into modal state. So the dataflow CodeQL found exists. It is the exploitability that does not:
{item.name}is JSX children. React escapes it. It is not an HTML sink, regardless of what a chart is named.hrefis guarded at:60-61(startsWith('/') && !startsWith('//')), and independently both URL sources are server-built fixed-prefix relative paths:Slice.url→/explore/?slice_id={int}(superset/models/slice.py:389-390) andDashboard.url→/dashboard/{slug or id}/(superset/models/dashboard.py:263-264). Character 1 is always a literal letter, sojavascript:,data:, and scheme-relative forms are all unreachable — the guard is belt-and-braces over already-safe values.
Suggest dismissing 2594 in the code-scanning UI as false positive with that justification rather than leaving it to block the merge.
One defence-in-depth note while you're in there: !startsWith('//') does not reject /\, which browsers normalise to a scheme-relative URL per the WHATWG URL spec (/\evil.com → http://evil.com). Not reachable here for the reason above, so this is not a finding against the current code — but the guard's comment claims it rejects "scheme-relative URLs" generally, and it doesn't quite. If it's meant to be reusable, matching /[^/\\] would make the comment true.
3. Confirmed clean — recording these because they were the things worth doubting
Unauthorized names do not reach the client. This was my main concern and the answer is good. collect_dataset_purge_impact deliberately runs under skip_visibility_filter (purge_impact.py:76) so count is authoritative — right call, a warning that hid dependents would defeat the feature. Redaction then happens at serialization: serialize_dataset_purge_impact (superset/commands/purge.py:226) gates every entry on can_access_chart / can_access_dashboard (:245, :253) and folds the rest into restricted_count (:264, :269). So only cardinality leaks, never names, UUIDs, or links. Your own integration test asserts exactly that — the restricted chart's UUID and name are absent from the serialized payload. The docs describe this honestly too. That's the right trade-off, correctly implemented.
The impact token is enforced server-side, not echoed. Twice: a fast-fail pre-check at superset/commands/purge.py:105, and — the one that actually matters — a re-collect and compare inside begin_nested() after claim.with_for_update() (purge_cascade.py:248,251-254). Both fail closed. Worth calling out that the integration test asserts the dataset still exists after the 409, which is the assertion that makes the guard meaningful rather than decorative.
Migration is convention-consistent. create_index does a plain blocking create with no CONCURRENTLY option, and zero migrations in the tree use CONCURRENTLY — every recent 2026 migration uses this same helper. downgrade() drops in correct reverse order. Not a defect. Flagging for operator awareness only: slices is large in real deployments and this will block writes on it for the duration of the build.
DeleteModal is backward compatible. All three new props are optional with behavior-preserving defaults (disablePrimaryButton = false, loading = false, confirmationResetKey undefined). The new useEffect resets to what is already the initial state on mount, and the composed disablePrimaryButton expression reduces to the old one when both are false. ~20 existing callers are unaffected.
Permission mapping. "purge_impact": "write" on a GET is deliberate and correct — it scopes the preview to the purge audience rather than the read audience.
4. Nit
index.tsx:384-392 casts the parsed error to Partial<PurgeImpactChangedResponse> and then only truthiness-checks parsedError.impact. A 409 from an intermediary with a different body shape would reach render and throw inside ImpactCollection on collection.result.slice(...). A shape check on impact.charts?.result would keep the error path from becoming its own error.
Verification. RAN: tests/unit_tests/commands/deletion_retention/ — 44 passed; full tests/unit_tests/commands/ — 970 passed. I also ran a mutation check, removing both token-enforcement branches: all 970 unit tests still passed, but that is expected and not a criticism — enforcement lives in soft_delete_tests.py / force_purge_tests.py, which run under test-postgres / test-mysql / test-sqlite and pass. A unit-level test of the mismatch branch would be cheap insurance, nothing more. INSPECTED (not run): all frontend tests — superset-frontend/node_modules is not installed in my environment, which is an environment limitation on my side and not a statement about this PR. Everything in §1–§3 is from reading code at the pinned SHA, with each cited line verified against 25781a051a.
Not approving as I'm not a committer on this repo — leaving that to a maintainer. The design here is sound; §1 is the one I'd want a decision on before this merges.
Code Review Agent Run #16267fActionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
aminghadersohi
left a comment
There was a problem hiding this comment.
approving with the comment above
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks @mikebridge, this is careful work on a genuinely dangerous flow, and the fail-closed shape of the modal is exactly right.
I went beyond reading the diff and verified this empirically:
- Ran the new unit tests plus the full deletion_retention and datasets unit suites (153 passed), the whole deletion_retention integration package (84 passed, 1 skipped), and the TestDatasetArchiveListing class (8 passed) on a fresh metadata DB.
- Ran both jest suites (38 passed). I also ran the new DeleteModal tests against the pre-PR component: the three new behaviors (loading, external disable, confirmationResetKey re-arm) fail there, so the tests pin the fix rather than the status quo.
- Verified the migration: upgrade, downgrade to 39097d124752, and re-upgrade all succeed on a fresh DB, with both indexes present afterwards.
- Exercised the endpoints on a live instance with SOFT_DELETE enabled: purge-impact returns the right counts, names, links, and token; purge with a missing or empty token answers 400; a bogus or stale token answers 409 with refreshed impact and mutates nothing; after adding a chart mid-flow the stale token was refused and the refreshed impact included it; confirming with the refreshed token purged the dataset while every dependent chart and the dashboard survived, and the audit row recorded the dangling chart UUIDs.
Two non-blocking notes:
- The two open js/xss-through-exception CodeQL alerts point at the impact list rendering. The flagged values render as React text nodes and an href gated to server-issued application paths (ArchivedDatasetPurgeModal.tsx, the isSafeAppPath check), so I read both as false positives and will dismiss them.
- Future-direction note, not a blocker: a dashboard can depend on a dataset solely through a native filter target (native_filter_configuration targets carry a datasetId; dashboard export already follows them in superset/models/dashboard.py), and such a dashboard would show as "0 Dashboards" here. That matches the existing related_objects discovery exactly, so it is parity rather than a regression, but it may be worth a follow-up covering both surfaces someday.
LGTM.
SUMMARY
With
SOFT_DELETEenabled, archiving a dataset warns about the charts and dashboards that depend on it — but permanently deleting that same dataset from Settings → Recently archived showed only a generic type-DELETE confirmation. The irreversible action carried less warning than the recoverable one, and confirming it silently orphaned every dependent chart (the non-cascade itself is intended behaviour:ForcePurgeCommandpreserves independently owned entities).This PR makes the permanent-delete confirmation for an archived dataset show the full dependency impact before the user can confirm:
GET /api/v1/dataset/<uuid>/purge-impact, returns the authoritative dependent-object counts (live and recoverable-archived charts and dashboards), the names/links the caller may see, an aggregaterestricted_countfor objects the caller cannot access (no names, UUIDs, or links leak), and a versioned SHA-256impact_tokenfingerprinting the exact affected set.impact_token. The purge re-collects impact at submit time and again under the dataset row lock inside the cascade; if the affected set changed since the user read the warning, the request mutates nothing and returns 409 with the refreshed impact, and the modal asks for a renewed confirmation (same TOCTOU shape as the version-restore guard). A post-write-ahead mismatch finalises its force-purge audit row asfailedwith zero removals.8f31c5d726ab) adds two small indexes used by the impact queries:slices(datasource_type, datasource_id)anddashboard_slices(slice_id).Design notes: dependents are deliberately not globally serialised — the guarantee is two submit-time rechecks, not an immutable set after the final snapshot (documented in the spec; a 7-lens review's serialisation finding was evaluated and rejected by design). Inaccessible dependents are counted but never named.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Archived dataset
purge_demowith two live dependent charts.Before — no mention of the two charts this purge will orphan:
After — authoritative counts, named and linked charts, explicit zero-state for dashboards, Delete gated on the typed confirmation:
TESTING INSTRUCTIONS
SOFT_DELETE. Create a dataset and build two charts on it./purge-impactin devtools and open the modal — an error state with Retry/Cancel appears and Delete cannot be reached.Automated:
test_purge_impact.py(canonical ordering, fingerprint stability, dashboard dedup, archived inclusion),soft_delete_tests.py(authorization incl. a caller with a restricted dependent; contract fields),force_purge_tests.py/purge_tests.py(matching/mismatched/same-count tokens, locked recheck, failed audit finalisation, token-free scheduled retention),ArchivedList.test.tsx(27 tests: loading, counts, badges, restricted aggregates, bounded lists, 409 renewal, error/retry, unchanged chart/dashboard flows),DeleteModal.test.tsx(external disable/loading/reset). Migration verified by upgrade→downgrade→re-upgrade on a fresh metadata DB, re-run after re-chaining onto39097d124752.ADDITIONAL INFORMATION
SOFT_DELETECREATE INDEXstatements onslicesanddashboard_slices; seconds on typical metadata volumes, no table rewrites, no downtime expectedThis description was drafted with Claude (AI) assistance on behalf of @mikebridge.
🤖 Generated with Claude Code