{"record":{"id":"f1881385b4050559","repo":"apache/superset","slug":"database-could-not-be-created","errorCode":null,"errorMessage":"Database could not be created.","messagePattern":"Database could not be created\\.","errorType":"exception","errorClass":"DatabaseCreateFailedError","httpStatus":500,"severity":"error","filePath":"superset/commands/database/create.py","lineNumber":118,"sourceCode":"            SSHTunnelCreateFailedError,\n            SSHTunnelingNotEnabledError,\n            SSHTunnelDatabasePortError,\n        ) as ex:\n            event_logger.log_with_context(\n                action=f\"db_creation_failed.{ex.__class__.__name__}.ssh_tunnel\",\n                engine=engine,\n            )\n            # So we can show the original message\n            raise\n        except (\n            DatabaseInvalidError,\n            Exception,\n        ) as ex:\n            event_logger.log_with_context(\n                action=f\"db_creation_failed.{ex.__class__.__name__}\",\n                engine=engine,\n            )\n            raise DatabaseCreateFailedError() from ex\n\n        return database\n\n    def validate(self) -> None:\n        exceptions: list[ValidationError] = []\n\n        sqlalchemy_uri: Optional[str] = self._properties.get(\"sqlalchemy_uri\")\n        if not sqlalchemy_uri:\n            exceptions.append(DatabaseRequiredFieldValidationError(\"sqlalchemy_uri\"))\n\n        database_name: Optional[str] = self._properties.get(\"database_name\")\n        if not database_name:\n            exceptions.append(DatabaseRequiredFieldValidationError(\"database_name\"))\n        else:\n            if not DatabaseDAO.validate_uniqueness(database_name):\n                exceptions.append(DatabaseExistsValidationError())\n\n        if exceptions:","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/create.py#L100-L136","documentation":"DatabaseCreateFailedError raised in CreateDatabaseCommand.run (create.py:118) from the except (DatabaseInvalidError, Exception) block around _create_database() and add_permissions(database). This is the terminal wrap for anything that goes wrong after the test connection succeeded — model-level validation failures, SSH tunnel errors, SQLAlchemy persistence problems in the metadata DB, or permission-sync errors. The @transaction decorator's on_error also reraises into this class.","triggerScenarios":"POST /api/v1/database/ where the payload passes connection testing but fails during persist: e.g. DatabaseInvalidError from validate() (missing database_name), SSHTunnel* errors raised while opening the tunnel, unique-constraint violation on database_name, or metadata DB errors during INSERT.","commonSituations":"Payload missing database_name (validation error collected earlier and surfaced during create); SSH tunnel settings (server, key) misconfigured; asynchronous SSH tunnel setup failing; duplicate database name; metadata DB constraint issues.","solutions":["Read __cause__ / server logs: db_creation_failed.<ExceptionName> is logged with context via event_logger and the original exception is chained.","Ensure database_name is present and unique — a duplicate name fails at persist time.","If using SSH tunneling, verify SSH_TUNNELING config, the tunnel credentials, and that SSHTunnel* errors are the real cause.","Fix any validate()-stage issues first (all required fields present) before retrying the POST."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"def create_payload_complete(data: dict) -> bool:\n    return all(data.get(f) for f in (\"database_name\", \"sqlalchemy_uri\"))","typeGuard":null,"tryCatchPattern":"from superset.commands.database.exceptions import DatabaseCreateFailedError\n\ntry:\n    db = CreateDatabaseCommand(data).run()\nexcept DatabaseCreateFailedError as ex:\n    cause = type(ex.__cause__).__name__ if ex.__cause__ else \"?\"\n    log.error(\"create failed, cause=%s\", cause)  # SSH tunnel / validation / metadata DB\n    raise","preventionTips":["Pass validate() first in your own flow (same fields) so failures surface before the transaction starts.","Pre-verify SSH tunnel config when using tunnels — tunnel errors land here after a successful test connection.","Watch for db_creation_failed.* events in stats logging to classify failure causes."],"tags":["database","create","ssh-tunnel","metadata-db","transaction"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}