apache/superset · error · DatabaseNotFoundError

Database not found.

Error message

Database not found.

What it means

DatabaseNotFoundError (HTTP 404) is raised in ValidatorSQLCommand.validate() when DatabaseDAO.find_by_id(self._model_id) returns None — the database id supplied to the validate_sql command does not correspond to an existing Database row.

Source

Thrown at superset/commands/database/validate_sql.py:150

                    "Please recheck your query.\n"
                    "Exception: %(ex)s",
                    validator=self._validator.name,
                    ex=ex,
                ),
                error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
                level=ErrorLevel.ERROR,
            )

            # Return as a 400 if the database error message says we got a 4xx error
            if re.search(r"([\W]|^)4\d{2}([\W]|$)", str(ex)):
                raise ValidatorSQL400Error(superset_error) from ex
            raise ValidatorSQLError(superset_error) from ex

    def validate(self) -> None:
        # Validate/populate model exists
        self._model = DatabaseDAO.find_by_id(self._model_id)
        if not self._model:
            raise DatabaseNotFoundError()

        spec = self._model.db_engine_spec
        validators_by_engine = app.config["SQL_VALIDATORS_BY_ENGINE"]
        if not validators_by_engine or spec.engine not in validators_by_engine:
            raise NoValidatorConfigFoundError(
                SupersetError(
                    message=__(
                        "no SQL validator is configured for %(engine_spec)s",
                        engine_spec=spec.engine,
                    ),
                    error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
                    level=ErrorLevel.ERROR,
                ),
            )
        validator_name = validators_by_engine[spec.engine]
        self._validator = get_validator_by_name(validator_name)
        if not self._validator:
            raise NoValidatorFoundError(

View on GitHub (pinned to f4587218dd)

Solutions

  1. Confirm the database id exists: GET /api/v1/database/<id> — if it 404s, pick a valid connection from GET /api/v1/database/.
  2. If the database was deleted, recreate the connection and re-issue the validation with the new id.
  3. In scripts, resolve the id by database_name at runtime instead of hardcoding it.

Example fix

# before
curl -X POST /api/v1/database/999/validate_sql -d '{"sql": "SELEC 1"}'

# after — resolve a live id first
db_id=$(curl -s /api/v1/database/ | jq '.result[0].id')
curl -X POST /api/v1/database/$db_id/validate_sql -d '{"sql": "SELEC 1"}'
Defensive patterns

Strategy: validation

Validate before calling

# Confirm the database id exists before validating SQL against it
from superset.databases.dao import DatabaseDAO

def database_exists(database_id: int) -> bool:
    return DatabaseDAO.find_by_id(database_id) is not None

Try / catch

from superset.commands.database.exceptions import DatabaseNotFoundError
try:
    ValidatorSQLCommand(database_id, payload).run()
except DatabaseNotFoundError:
    # 404: re-resolve a live database id and prompt the user to reselect
    refresh_database_picker()

Prevention

When it happens

Trigger: POST /api/v1/database/validate_sql with a `database_id` (or path parameter) that is deleted or never existed; the Database row being deleted between the client loading the picker and submitting the request; passing a string id that coerces to a non-matching value.

Common situations: Stale frontend state after an admin deletes a database connection; scripts reusing recorded database ids against a fresh metadata DB; environment mismatch (dev id referenced against prod metadata).

Related errors


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/27c76c0283b42950. Report an issue: GitHub.