Skip to content

fix(dataset): return an actionable error when an archived dataset holds the name - #46376

Open
zhengdaodeguL wants to merge 2 commits into
apache:masterfrom
zhengdaodeguL:fix/archived-dataset-error-46365
Open

zhengdaodeguL wants to merge 2 commits into
apache:masterfrom
zhengdaodeguL:fix/archived-dataset-error-46365

Conversation

@zhengdaodeguL

Copy link
Copy Markdown
Contributor

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:

  • New regression test 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 check and ruff format --check on the touched Python files pass; git diff --check clean.
  • Full backend suite, frontend E2E, and live-instance verification are left to CI.

…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.
Comment on lines +238 to +240
raise DatasetSoftDeletedTwinExistsError(
str(soft_twin.uuid), dataset_name=str(soft_twin.table_name)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

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
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging because the new error names only the table, leaving users with same-named datasets in different schemas or catalogs unsure which archived entry to restore or delete.

Assessed commit: 929682db06d1

@github-actions github-actions Bot added api Related to the REST API doc Namespace | Anything related to documentation labels Nov 19, 2026
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 65.55%. Comparing base (f357ec3) to head (59ec1b9).
⚠️ Report is 140 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/dataset/exceptions.py 75.00% 0 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (f357ec3) and HEAD (59ec1b9). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (f357ec3) HEAD (59ec1b9)
python 5 3
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     
Flag Coverage Δ
hive ?
mysql 51.66% <80.00%> (-0.01%) ⬇️
postgres 51.70% <80.00%> (?)
presto ?
python 51.88% <80.00%> (-36.42%) ⬇️
sqlite 51.37% <80.00%> (-0.01%) ⬇️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 in create_virtual_dataset.py). Both tools return str(exc). Before this change, an agent got the archived dataset's UUID, which restore_dataset accepts directly. Now it gets a UI-oriented "Recently Archived" message and has to find the dataset through list_datasets with trashed rows first. Keeping self.dataset_uuid on 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. Passing dataset_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.

Comment on lines +239 to +241
'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.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

Suggested change
'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.

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API doc Namespace | Anything related to documentation requires:rebase Requires rebasing on top of current master size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An error occurred while creating datasets (archive)

3 participants