Repository navigation
fix(dataset): return an actionable error when an archived dataset holds the name - #46376
zhengdaodeguL wants to merge 2 commits into
Conversation
…he#46365) When a dataset with the same name already exists in Recently Archived, creation returned a technical 422 naming a UUID and a restore endpoint. Surface a clear message naming the archived dataset and telling the user to restore it or delete it permanently before creating a replacement. Active-duplicate behavior and archiving semantics are unchanged.
| raise DatasetSoftDeletedTwinExistsError( | ||
| str(soft_twin.uuid), dataset_name=str(soft_twin.table_name) | ||
| ) |
There was a problem hiding this comment.
Suggestion: When archived datasets share a table name across schemas or catalogs, Recently Archived displays only that name, so this error cannot identify which row to restore or purge.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Incomplete implementation
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/commands/dataset/create.py
**Line:** 238:240
**Comment:**
*Incomplete Implementation: When archived datasets share a table name across schemas or catalogs, Recently Archived displays only that name, so this error cannot identify which row to restore or purge.
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #46376 +/- ##
===========================================
- Coverage 85.66% 65.55% -20.12%
===========================================
Files 3111 3111
Lines 214938 214939 +1
Branches 50908 50909 +1
===========================================
- Hits 184136 140900 -43236
- Misses 27381 70833 +43452
+ Partials 3421 3206 -215
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:
|
mikebridge
left a comment
There was a problem hiding this comment.
Thanks, this is a real improvement. The new message is readable, the status code and response shape are unchanged, and naming the dataset doesn't disclose anything new: find_soft_deleted_logical_duplicate matches the exact name the user just typed, in the same database, catalog and schema. Dropping the UUID also means the error reveals less than before. I'd like one wording change before approving.
The one change I'd like is inline: see the suggestion on superset/commands/dataset/exceptions.py:239-241
Two smaller, non-blocking points:
- MCP callers lose the restorable ID (
superset/mcp_service/dataset/tool/create_dataset.py:200, and the same increate_virtual_dataset.py). Both tools returnstr(exc). Before this change, an agent got the archived dataset's UUID, whichrestore_datasetaccepts directly. Now it gets a UI-oriented "Recently Archived" message and has to find the dataset throughlist_datasetswith trashed rows first. Keepingself.dataset_uuidon the exception and having those two handlers include it would preserve that path. - Renaming still shows the technical message (
superset/commands/dataset/update.py:265). That path raises the error without a name. Renaming an existing dataset onto an archived dataset's name still produces the UUID-and-endpoint text from #46365. Passingdataset_name=there as well would make both paths consistent; a follow-up is fine.
On CI: every red check on this head comes from the 2026-11-19 run, where the changes jobs hit "API rate limit exceeded", so the backend and frontend suites never actually ran. A re-run (or a fresh push) is needed before this can be judged green.
| 'Dataset "%(name)s" already exists in Recently Archived. ' | ||
| "Restore it to use the existing dataset, or delete it permanently " | ||
| "before creating a new dataset with the same name.", |
There was a problem hiding this comment.
The previous message ended "…or use a different table name", and that option is gone. Restore and Delete permanently are limited to the dataset's editors and admins, so a user who can create datasets on this database but never owned the archived one gets no action they can take. Suggest restoring the alternative and adding an ask-an-owner-or-admin path:
| 'Dataset "%(name)s" already exists in Recently Archived. ' | |
| "Restore it to use the existing dataset, or delete it permanently " | |
| "before creating a new dataset with the same name.", | |
| 'Dataset "%(name)s" already exists in Recently Archived. ' | |
| "Restore it or delete it permanently from Recently Archived, " | |
| "or use a different name. If you can't restore it, ask one of " | |
| "its owners or an admin.", |
The docs paragraph in recently-archived.mdx would want the same addition.
Fixes #46365
When a dataset with the same name already exists in Recently Archived, creating a new dataset with that name failed with a technical 422 message containing a UUID and a restore endpoint (
A soft-deleted dataset (uuid ...) already references this table. Restore it via POST /api/v1/dataset/.../restore ...), and the creation aborted. Archived datasets are excluded from the dataset selector's active lookup, so the selector's duplicate-name warning misses them, and the creation path's existing soft-deleted-duplicate detection (DatasetDAO.find_soft_deleted_logical_duplicate) was the only signal — in technical form.This reuses that detection and only changes the message: when the dataset name is known, the error now reads
Dataset "..." already exists in Recently Archived. Restore it to use the existing dataset, or delete it permanently before creating a new dataset with the same name.The old UUID/endpoint message is kept as the fallback when no name is available. Archiving semantics and non-archived duplicate behavior are unchanged (an active duplicate still returns{"table": ["Dataset ... already exists"]}), and the docs now explain that archived datasets still hold the name and how to restore or permanently delete them.Verification:
test_post_dataset_with_archived_duplicate_returns_actionable_422(parameterized over physical and virtual datasets): create a dataset, confirm the active-duplicate 422 on a second create, archive it (soft delete), then create the same name again and assert the clear 422 message — fails before the fix, passes after.pytest tests/unit_tests/commands/dataset/test_create.py tests/unit_tests/datasets/api_tests.py tests/unit_tests/datasets/dao/dao_tests.py: 76 passed.ruff checkandruff format --checkon the touched Python files pass;git diff --checkclean.