Repository navigation
fix(databases): surface dataset dependents in the delete confirmation - #44392
Conversation
Deleting a database connection is refused while any dataset still references it (DeleteDatabaseCommand.validate), but the confirmation modal only enumerated charts, dashboards and SQL Lab tabs. A connection whose only dependents were datasets therefore read as "linked to 0 charts that appear on 0 dashboards" and promised that deleting "will break those objects" -- the user learned the delete was blocked only after typing DELETE and confirming, from a toast. Return a datasets block from the related_objects endpoint and render it in the modal, and say the delete is blocked rather than destructive when datasets are attached. The datasets are counted with the soft-delete visibility filter bypassed, matching how validate() counts them: database.tables hides soft-deleted datasets, which would otherwise let the preview report zero dependents for a connection the delete still refuses.
The datasets block added to this endpoint returned every dataset name and schema on the connection. The route only requires can_read on Database, and DatabaseFilter admits a caller holding datasource_access on a single dataset in that database, so the response let such a caller enumerate datasets they hold no permission on. Filter the names with can_access_datasource, matching how charts and dashboards are already filtered, and keep the count unfiltered so the confirmation can still explain why the delete is blocked. The modal now derives its overflow footer from what is actually listed, and renders no list at all when none of the blocking datasets are visible.
Code Review Agent Run #03994dActionable Suggestions - 0Additional Suggestions - 3
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 |
`related_objects` gained a `datasets` field, so the published spec no longer matches what `superset update-api-docs` generates. Regenerate it: the diff is limited to the two new component schemas and the added `$ref`.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #44392 +/- ##
===========================================
+ Coverage 57.12% 81.08% +23.96%
===========================================
Files 2955 2955
Lines 178324 178374 +50
Branches 41313 41325 +12
===========================================
+ Hits 101869 144638 +42769
+ Misses 75475 31025 -44450
- Partials 980 2711 +1731
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:
|
EnxDev
left a comment
There was a problem hiding this comment.
The dependency count matches the backend delete guard, including archived datasets, and the access filtering keeps the names scoped appropriately. I left one comment on the cleanup guidance and a smaller UX suggestion for the blocked state.
Validation: all 5 focused backend tests and all 8 dataset-dependent modal tests passed. Pre-commit passed except for frontend type checking, which hit missing generated workspace declarations (TS6305) in the temporary checkout; I could not complete that check. I did not verify the UI in a running Superset instance.
| 'cannot be deleted because %s dataset is still attached to it. Delete or move that dataset first.', | ||
| 'cannot be deleted because %s datasets are still attached to it. Delete or move those datasets first.', |
There was a problem hiding this comment.
Could we make the cleanup guidance cover archived datasets here? With SOFT_DELETE enabled (the default), removing a dataset from the dataset list archives it, so it still contributes to this count and blocks the connection delete. Once only archived datasets remain, the normal dataset list is empty, and “Delete or move” gives the user no next step. Disabling the button also means they never see DatabaseDeleteSoftDeletedDatasetsExistFailedError, which explains the purge flow. Pointing them to Recently archived → Delete permanently, and covering the archived-only case in the modal tests, would make this actionable.
There was a problem hiding this comment.
Good catch. I updated the blocked copy to point users to Recently archived → Delete permanently, and added coverage for the archived-only case.
| }} | ||
| onHide={() => setDatabaseCurrentlyDeleting(null)} | ||
| open | ||
| disablePrimaryButton={databaseCurrentlyDeleting.datasets.count >= 1} |
There was a problem hiding this comment.
Small UX suggestion: could the blocked state use an informational modal with a Close action and no confirmation input? DeleteModal still renders and focuses “Type DELETE to confirm”, even though typing it can never enable the button here. The new disabled-action test confirms that behavior. Hiding that prompt while datasets are attached would avoid inviting the user to complete a step that cannot do anything.
There was a problem hiding this comment.
Agreed. I kept the modal structure consistent, but the confirmation input is now disabled and no longer focused whenever deletion is blocked; the primary action stays disabled too. Covered in both the shared modal and database-list tests.
EnxDev
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. I reviewed the updated copy, the shared DeleteModal change, and the batched dataset lookup. The archived-dataset guidance addresses my earlier comment, and disabling the confirmation input avoids inviting users to type into a blocked action. I found no additional actionable issues in this pass.
Validation: 87 frontend tests passed across the database deletion, shared confirmation, and archived-item flows. The 6 related-object backend tests also passed, plus an extra local batching check: two entirely inaccessible pages followed by authorized datasets, including an archived row. That check confirmed the full count is preserved and the response stops at 10 authorized names.
Pre-commit passed except frontend type checking, which remains blocked locally by missing generated workspace declarations (TS6305). Live UI verification was unavailable.
🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️❗ @geido Your base branch
|
Code Review Agent Run #f3ebffActionable 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 |
|
Heya @geido, nice write-up on this one. One thing before it can merge, though: CI's failind due to this diff.
Say the word if you want a hand tackling any of the above. |
|
| query = cls._related_datasets_query(database_id) | ||
| if last_id is not None: | ||
| query = query.filter(SqlaTable.id > last_id) | ||
| batch = query.order_by(SqlaTable.id).limit(RELATED_DATASET_BATCH_SIZE).all() | ||
| if not batch: | ||
| return | ||
| yield from batch |
There was a problem hiding this comment.
Suggestion: When fewer than ten datasets are accessible, this iterator scans every related row in batches, making modal requests scale with all hidden datasets.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Performance
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/daos/database.py
**Line:** 73:79
**Comment:**
*Performance: When fewer than ten datasets are accessible, this iterator scans every related row in batches, making modal requests scale with all hidden datasets.
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.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| class DatabaseRelatedDataset(Schema): | ||
| id = fields.Integer() | ||
| table_name = fields.String() | ||
| schema = fields.String() |
There was a problem hiding this comment.
Suggestion: Dataset schemas may be NULL, but this response schema declares schema as non-nullable, so generated API clients reject valid responses.
Assessment: 🟠 Major · 🔁 Occurrence: Often · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/databases/schemas.py
**Line:** 950:950
**Comment:**
*Api Mismatch: Dataset schemas may be NULL, but this response schema declares `schema` as non-nullable, so generated API clients reject valid responses.
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.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
Thanks @rusackas — fixed the shared modal so |
There was a problem hiding this comment.
Code Review Agent Run #f0493f
Actionable Suggestions - 1
-
superset-frontend/packages/superset-ui-core/src/components/DeleteModal/types.ts - 1
- Misleading prop name · Line 53-53
Additional Suggestions - 1
-
superset-frontend/src/pages/DatabaseList/index.tsx - 1
-
duplicated block condition · Line 1334-1336The condition `databaseCurrentlyDeleting.datasets.count >= 1` is now repeated at lines 1206, 1333, and 1335. If the blocking rule changes, all three must stay in sync or the message/button/input states diverge. Consider extracting `const deleteBlocked = databaseCurrentlyDeleting.datasets.count >= 1;` and reusing it in all three places.
-
Review Details
-
Files reviewed - 5 · Commit Range:
1250e2c..057cefd- superset-frontend/packages/superset-ui-core/src/components/DeleteModal/DeleteModal.test.tsx
- superset-frontend/packages/superset-ui-core/src/components/DeleteModal/index.tsx
- superset-frontend/packages/superset-ui-core/src/components/DeleteModal/types.ts
- superset-frontend/src/pages/DatabaseList/index.tsx
- superset/translations/messages.pot
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
- Eslint (Linter) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers an incremental AI Review. -
/review full- Manually triggers a full AI Review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
| /** Disable the primary action independently of the typed-text gate. */ | ||
| disablePrimaryButton?: boolean; | ||
| /** Disable the confirmation input and primary action when deletion is blocked. */ | ||
| disableConfirmationInput?: boolean; |
There was a problem hiding this comment.
disableConfirmationInput also disables the primary action via confirmationBlocked (index.tsx:56-57), overlapping disablePrimaryButton. The DatabaseList consumer sets both to the same value (index.tsx:1333-1336), showing the overlap is confusing. A name like disableConfirmation would reflect that it gates the whole flow.
Code Review Run #f0493f
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
SUMMARY
Deleting a database connection opens a confirmation modal that enumerates the objects the delete will affect. That preview counted charts, dashboards and SQL Lab tabs — but not datasets, because
GET /api/v1/database/<id>/related_objects/never returned them.That is the one dependency class the delete actually refuses on.
DeleteDatabaseCommand.validate()raisesDatabaseDeleteDatasetsExistFailedError(HTTP 422) while anySqlaTablerow references the database, so for a connection whose only dependents are datasets the modal read:…which asserts nothing will break, and gates a confirmation that cannot succeed. The user types
DELETE, confirms, and getsThere was an issue deleting qa_warehouse: Cannot delete a database that has datasets attached— with the same misleading modal still on screen.This adds datasets to the preview and rewords the confirmation when they are present:
DatabaseDAO.get_related_objectsreturns theSqlaTablerows referencing the database. It queries them underskip_visibility_filter, exactly asDeleteDatabaseCommand.validate()does —Database.tableshides soft-deleted datasets, which would otherwise let the preview report zero dependents for a database the delete still refuses.related_objectsgains adatasetsblock (count,result[{id, table_name, schema}]) andDatabaseRelatedObjectsResponsedocuments it.Design decision worth reviewing: dataset names are access-filtered with
security_manager.can_access_datasource, the same way chart and dashboard names already are. The count is deliberately left unfiltered. This route only requirescan_readonDatabase, andDatabaseFilteradmits a caller holdingdatasource_accesson a single dataset in that database — returning every name would let them enumerate datasets they hold no permission on. The count has to stay unfiltered because it is what explains the delete being blocked, and a bare number discloses far less than a name and schema. Both halves are pinned by tests. Theresultlist is capped at ten authorized datasets—the same maximum the modal renders—whilecountremains complete; candidate details are read in bounded batches so the endpoint does not materialize or serialize every dataset.The frontend tolerates a backend that predates the
datasetsblock (json.datasets ?? { count: 0, result: [] }), so a version-skewed deployment degrades to the previous copy rather than throwing.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Verified in a running instance against a connection (
qa_warehouse) whose only dependents are two datasets — no charts, no dashboards, no SQL Lab tabs. Exact modal text, captured from the app in both states:Before — the preview reports nothing attached, and invites the delete:
Typing
DELETEand confirming then fails, because the backend refuses it:After — the preview names what is actually blocking the delete:
A connection with no datasets is byte-identical to before — the ordinary "Are you sure you want to continue?" confirmation is untouched.
TESTING INSTRUCTIONS
Automated:
Manual:
0 charts / 0 dashboards / 0 SQL Lab tabsand offered to continue.To check the access-filtering: as a user holding
datasource_accesson only one of several datasets in the connection, the modal counts them all but names only the accessible one.ADDITIONAL INFORMATION