apache/superset · error · DatabaseNotFoundError
Database not found.
Error message
Database not found.
What it means
DatabaseNotFoundError is raised by the SyncPermissionsCommand.db_connection property when the internal _db_connection reference is still None. The command lazily resolves the Database model either from a passed-in instance or from db_connection_id in validate(); accessing db_connection before a successful resolution trips this guard.
Source
Thrown at superset/commands/database/sync_permissions.py:83
username: str | None,
old_db_connection_name: str | None = None,
db_connection: Database | None = None,
):
"""
Constructor method.
"""
self.db_connection_id = model_id
self.username = username
self._old_db_connection_name: str | None = old_db_connection_name
self._db_connection: Database | None = db_connection
self._user_id: int | None = None
self.async_mode: bool = app.config["SYNC_DB_PERMISSIONS_IN_ASYNC_MODE"]
@property
def db_connection(self) -> Database:
if not self._db_connection:
raise DatabaseNotFoundError()
return self._db_connection
@property
def old_db_connection_name(self) -> str:
return (
self._old_db_connection_name
if self._old_db_connection_name is not None
else self.db_connection.database_name
)
def validate(self) -> None:
self._db_connection = (
self._db_connection
if self._db_connection
else DatabaseDAO.find_by_id(self.db_connection_id)
)
if not self._db_connection:
raise DatabaseNotFoundError()View on GitHub (pinned to f4587218dd)
Solutions
- Call command.validate() (or run()) before touching command.db_connection or old_db_connection_name
- Verify the database id exists first: DatabaseDAO.find_by_id(model_id) returns a row
- If invoking from the API layer, ensure the Database connection REST endpoint passes an existing model id
Example fix
// before cmd = SyncPermissionsCommand(db_id, username) name = cmd.old_db_connection_name # may raise DatabaseNotFoundError // after cmd = SyncPermissionsCommand(db_id, username) cmd.validate() # resolves _db_connection or raises early name = cmd.old_db_connection_name
Defensive patterns
Strategy: validation
Validate before calling
from superset.databases.dao import DatabaseDAO
model = DatabaseDAO.find_by_id(db_id)
if model is None:
raise LookupError(f"no database {db_id}")
cmd = SyncPermissionsCommand(db_id, username, db_connection=model)
cmd.validate() # populates _db_connection before property access Try / catch
try:
cmd.validate()
except DatabaseNotFoundError:
# handle missing connection
... Prevention
- Always call validate()/run() before reading command properties
- Pass a pre-fetched Database object when you have one
When it happens
Trigger: Constructing SyncPermissionsCommand without a db_connection kwarg and reading command.db_connection (directly or via old_db_connection_name) before calling validate(); or calling it after validate() failed to resolve the id.
Common situations: Custom code or tests that instantiate the command and poke properties out of order; race where the database row was deleted between construction and property access.
Related errors
- Field is required
- Database doesn't exist and user doesn't have permission to c
- Database not found.
- Database parameters are invalid.
- Database not found
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/6b668fb725b6190f.
Report an issue: GitHub.