apache/superset · error · SupersetErrorException
The database was not found.
Error message
The database was not found.
What it means
SupersetErrorException with DATABASE_NOT_FOUND_ERROR (HTTP 404, 'The database was not found.') is raised inside the dataset duplicate command's run() when db.session.get(Database, database_id) returns None — the base dataset's stored database_id no longer matches any Database row. The base dataset itself passed validation, so this indicates its connection was deleted (or the metadata is inconsistent) between validate() and run().
Solutions
- Check the base dataset's database reference (GET /api/v1/dataset/<base_model_id> shows database id) and verify GET /api/v1/database/<id> resolves.
- If the database was deleted, recreate the connection (same engine/URI) so the orphaned dataset becomes usable, then retry the duplicate.
- Clean up or re-point orphaned datasets before duplicating them; retrying immediately will keep failing with 404.
Defensive patterns
Strategy: validation
Validate before calling
# Ensure the base dataset's database still exists before duplicating
from superset.models.core import Database
from superset import db
def base_database_exists(base_model) -> bool:
return (
base_model is not None
and db.session.get(Database, base_model.database_id) is not None
) Try / catch
from superset.errors import SupersetErrorException
try:
DuplicateDatasetCommand(base_id, properties).run()
except SupersetErrorException as ex:
if ex.error.error_type.name == "DATABASE_NOT_FOUND_ERROR":
# orphaned base dataset: prompt admin to recreate the connection
prompt_recreate_database(base_dataset.database_name)
else:
raise Prevention
- When deleting a database connection, clean up or export its datasets in the same operation.
- Periodically scan for datasets whose database_id has no Database row (orphan report).
- After metadata-DB restores, verify referential integrity of dataset->database links.
When it happens
Trigger: POST /api/v1/dataset/duplicate with base_model_id whose dataset references a deleted database connection; the database row removed concurrently while the duplicate request executes; metadata restored from a backup where datasets outlived their databases.
Common situations: Admin deletes a database connection without cascading cleanup of its datasets; environment migrations that copy datasets but not databases; race between database deletion and an in-flight duplicate.
Related errors
- Database not found.
- Dataset column not found.
- Dataset does not exist
- Dataset parameters are invalid.
- You don't have access to this dataset.
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/e91ebb4402fcd0d4.
Report an issue: GitHub.
Appendix: source
Thrown at superset/commands/dataset/duplicate.py:70
@transaction(on_error=partial(on_error, reraise=DatasetDuplicateFailedError))
def run(self) -> Model:
self.validate()
# Declare the high-level avenue before the duplicate touches
# the session. The change-record listener stamps
# ``version_transaction.action_kind = 'clone'`` so the new
# dataset's baseline records read as a clone in the timeline.
# Method-scoped import — defers the versioning bootstrap path
# out of this command's module-load graph; see ``changes.py``
# module docstring for the broader init-order rationale.
from superset.versioning.changes import ACTION_KIND_CLONE, ACTION_KIND_KEY
db.session.info[ACTION_KIND_KEY] = ACTION_KIND_CLONE
database_id = self._base_model.database_id
table_name = self._properties["table_name"]
editors = self._properties["editors"]
database = db.session.get(Database, database_id)
if not database:
raise SupersetErrorException(
SupersetError(
message=__("The database was not found."),
error_type=SupersetErrorType.DATABASE_NOT_FOUND_ERROR,
level=ErrorLevel.ERROR,
),
status=404,
)
table = SqlaTable()
table.override(self._base_model)
table.table_name = table_name
table.editors = editors
table.database = database
table.is_sqllab_view = True
if table.sql:
table.sql = table.sql.strip().strip(";")
db.session.add(table)
columns = [View on GitHub (pinned to f4587218dd)