{"record":{"id":"ffab46a643e13a5b","repo":"apache/superset","slug":"database-not-found-ffab46","errorCode":null,"errorMessage":"Database not found.","messagePattern":"Database not found\\.","errorType":"exception","errorClass":"DatabaseNotFoundError","httpStatus":404,"severity":"error","filePath":"superset/commands/database/tables.py","lineNumber":179,"sourceCode":"                    for mv in materialized_views\n                ],\n                key=lambda item: item[\"value\"],\n            )\n\n            payload = {\n                \"count\": len(tables) + len(views) + len(materialized_views),\n                \"result\": options,\n            }\n            return payload\n        except SupersetException:\n            raise\n        except Exception as ex:\n            raise DatabaseTablesUnexpectedError(str(ex)) from ex\n\n    def validate(self) -> None:\n        self._model = cast(Database, DatabaseDAO.find_by_id(self._db_id))\n        if not self._model:\n            raise DatabaseNotFoundError()\n","sourceCodeStart":161,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/tables.py#L161-L180","documentation":"DatabaseNotFoundError raised in DatabaseTablesCommand.validate() when DatabaseDAO.find_by_id(self._db_id) returns None. The tables-listing command requires an existing database connection row before it can enumerate tables.","triggerScenarios":"Calling GET /api/v1/database/<id>/tables/ (or the command directly) with an id that does not exist; connection deleted after the frontend cached its id.","commonSituations":"Stale browser tab referencing a deleted connection; API scripts with hardcoded ids; cross-environment id confusion.","solutions":["Fetch the database list and use a valid id","Refresh the frontend if it holds a stale connection reference","Restore the deleted connection if it was removed in error"],"exampleFix":"// before\n TablesCommand(999, {}).run()\n\n// after\n if not DatabaseDAO.find_by_id(999):\n     raise DatabaseNotFoundError()\n TablesCommand(999, {}).run()","handlingStrategy":"validation","validationCode":"if not DatabaseDAO.find_by_id(db_id):\n    raise LookupError(f\"database {db_id} does not exist\")\npayload = DatabaseTablesCommand(db_id, {}).run()","typeGuard":null,"tryCatchPattern":"try:\n    DatabaseTablesCommand(db_id, {}).run()\nexcept DatabaseNotFoundError:\n    # return 404 / refresh ids\n    ...","preventionTips":["Treat connection ids as volatile; re-fetch lists per session"],"tags":["database","not-found","validation"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}