{"record":{"id":"ea627949b70bdd21","repo":"apache/superset","slug":"database-not-found-ea6279","errorCode":null,"errorMessage":"Database not found","messagePattern":"Database not found","errorType":"exception","errorClass":"DatabaseNotFoundError","httpStatus":404,"severity":"error","filePath":"superset/commands/database/oauth2.py","lineNumber":123,"sourceCode":"                \"database_id\": self._state[\"database_id\"],\n                \"access_token\": token_response[\"access_token\"],\n                \"access_token_expiration\": expiration,\n                \"refresh_token\": token_response.get(\"refresh_token\"),\n            },\n        )\n\n    def validate(self) -> None:\n        if error := self._parameters.get(\"error\"):\n            raise OAuth2Error(error)\n\n        self._state = decode_oauth2_state(self._parameters[\"state\"])\n\n        if database := DatabaseUserOAuth2TokensDAO.get_database(\n            self._state[\"database_id\"]\n        ):\n            self._database = database\n        else:\n            raise DatabaseNotFoundError(\"Database not found\")\n","sourceCodeStart":105,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/oauth2.py#L105-L124","documentation":"DatabaseNotFoundError('Database not found') raised at oauth2.py:123 in OAuth2StoreTokenCommand.validate: the state parameter decoded fine and carries a database_id, but DatabaseUserOAuth2TokensDAO.get_database(state['database_id']) returns no Database row. The database that initiated the OAuth2 flow no longer exists (or the state was crafted with a bogus id).","triggerScenarios":"GET /oauth2/authorize completing a flow whose database was deleted between the authorize redirect and the callback; a state JWT signed with a stale/foreign database_id; the database hard-deleted by an admin mid-flow.","commonSituations":"Admin decommissions a database while a user sits on the provider consent screen; environments where state strings are reused/bookmarked; database deleted and re-created with a new id.","solutions":["Confirm the database still exists: GET /api/v1/database/ and re-initiate the connection flow from SQL Lab for the (new) database.","Never bookmark or replay OAuth2 callback URLs — always start from the connection dialog.","If the database was re-created, note it has a new id; the old state will never resolve."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from superset.daos.database import DatabaseUserOAuth2TokensDAO\nfrom superset.utils.oauth2 import decode_oauth2_state\n\ndef state_references_live_database(state_jwt: str) -> bool:\n    state = decode_oauth2_state(state_jwt)\n    return DatabaseUserOAuth2TokensDAO.get_database(state[\"database_id\"]) is not None","typeGuard":null,"tryCatchPattern":"from superset.commands.database.exceptions import DatabaseNotFoundError\n\ntry:\n    OAuth2StoreTokenCommand(params).run()\nexcept DatabaseNotFoundError:\n    # the initiating database was deleted mid-flow: restart from a live database\n    refresh_database_list()","preventionTips":["Never bookmark or replay OAuth2 callback URLs; always start from the connection dialog of a live database.","Coordinate database decommissioning with in-flight user sessions.","After a database is re-created it has a new id — old state strings will never resolve."],"tags":["oauth2","database","not-found","state","authentication"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}