{"record":{"id":"bc7a11824415036b","repo":"apache/superset","slug":"a-soft-deleted-dataset-uuid-uuid-s-already-ref","errorCode":null,"errorMessage":"A soft-deleted dataset (uuid %(uuid)s) already references this table. Restore it via POST /api/v1/dataset/%(uuid)s/restore before uploading, or upload to a different table name.","messagePattern":"A soft-deleted dataset \\(uuid (.+?)\\) already references this table\\. Restore it via POST /api/v1/dataset/(.+?)/restore before uploading, or upload to a different table name\\.","errorType":"exception","errorClass":"DatabaseUploadSoftDeletedDatasetExistsError","httpStatus":422,"severity":"error","filePath":"superset/commands/database/uploaders/base.py","lineNumber":211,"sourceCode":"            # hidden row — permanently blocking its restore — or die on the\n            # legacy unique constraint. Check BEFORE ``reader.read`` writes\n            # the file's contents into the analytics database: that write is\n            # outside this command's metadata transaction and would not roll\n            # back. With SOFT_DELETE off, leftover soft-deleted rows are\n            # visible to the lookup above, so this branch is never reached\n            # for them (degraded-mode semantics, consistent with the create\n            # paths).\n            # Deferred import: daos.dataset pulls in views.base, which\n            # circularly imports back into the commands package at app init\n            # (same constraint documented in daos/dataset.py re: PR #40573).\n            from superset.daos.dataset import (  # noqa: PLC0415\n                DatasetDAO,\n            )\n\n            if soft_twin := DatasetDAO.find_soft_deleted_logical_duplicate(\n                self._model, Table(self._table_name, self._schema)\n            ):\n                raise DatabaseUploadSoftDeletedDatasetExistsError(str(soft_twin.uuid))\n\n        self._reader.read(self._file, self._model, self._table_name, self._schema)\n\n        if not sqla_table:\n            sqla_table = SqlaTable(\n                table_name=self._table_name,\n                database=self._model,\n                database_id=self._model_id,\n                editors=editors,\n                schema=self._schema,\n            )\n            db.session.add(sqla_table)\n\n        sqla_table.fetch_metadata()\n\n    @staticmethod\n    def _file_size_bytes(file: Any) -> Optional[int]:\n        \"\"\"","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/uploaders/base.py#L193-L229","documentation":"DatabaseUploadSoftDeletedDatasetExistsError is raised when DatasetDAO.find_soft_deleted_logical_duplicate finds a soft-deleted dataset whose database/schema/table tuple matches the upload target. Superset blocks silent shadow-dataset creation and tells you to restore the twin via POST /api/v1/dataset/<uuid>/restore or pick another table name.","triggerScenarios":"Uploading a CSV to a table whose dataset was previously 'deleted' in the UI (soft delete); re-uploading after a dataset cleanup.","commonSituations":"Users delete a dataset in Explore, then try to re-upload the same table; recycled table names after dataset pruning.","solutions":["Restore the soft-deleted dataset first: POST /api/v1/dataset/<uuid>/restore (uuid is in the error message)","Or upload to a different table name","Or permanently purge the soft-deleted dataset if restore is not wanted"],"exampleFix":"// before\n UploadCommand(db_id, \"sales\", file, schema, reader).run()\n\n// after\n # after restoring the dataset named in the error:\n # POST /api/v1/dataset/<uuid>/restore\n UploadCommand(db_id, \"sales\", file, schema, reader).run()","handlingStrategy":"validation","validationCode":"from sqlalchemy import Table\nfrom superset.daos.dataset import DatasetDAO\n\ntwin = DatasetDAO.find_soft_deleted_logical_duplicate(\n    database, Table(table_name, schema)\n)\nif twin:\n    # restore it or choose another table name BEFORE uploading\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    UploadCommand(...).run()\nexcept DatabaseUploadSoftDeletedDatasetExistsError as e:\n    uuid = e.args[0]  # twin dataset uuid\n    # POST /api/v1/dataset/<uuid>/restore, then retry\n    ...","preventionTips":["Check for soft-deleted twins before re-uploading known table names","Prefer restoring datasets over shadow uploads"],"tags":["dataset","upload","soft-delete","conflict"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}