{"record":{"id":"cf25277a374eda68","repo":"apache/superset","slug":"theme-not-found-cf2527","errorCode":null,"errorMessage":"Theme not found.","messagePattern":"Theme not found\\.","errorType":"exception","errorClass":"ThemeNotFoundError","httpStatus":500,"severity":"error","filePath":"superset/commands/theme/set_system_theme.py","lineNumber":61,"sourceCode":"        # Clear all existing system defaults in a single query\n        db.session.execute(\n            update(Theme)\n            .where(Theme.is_system_default.is_(True))\n            .values(is_system_default=False)\n        )\n\n        # Set the new system default\n        self._theme.is_system_default = True\n        db.session.add(self._theme)\n\n        logger.info(\"Set theme %s as system default\", self._theme_id)\n\n        return self._theme\n\n    def validate(self) -> None:\n        self._theme = ThemeDAO.find_by_id(self._theme_id)\n        if not self._theme:\n            raise ThemeNotFoundError()\n\n\nclass SetSystemDarkThemeCommand(BaseCommand):\n    def __init__(self, theme_id: int):\n        self._theme_id = theme_id\n        self._theme: Optional[Theme] = None\n\n    @transaction(on_error=partial(on_error, reraise=Exception))\n    def run(self) -> Theme:\n        self.validate()\n        assert self._theme\n\n        # Clear all existing system dark themes in a single query\n        db.session.execute(\n            update(Theme)\n            .where(Theme.is_system_dark.is_(True))\n            .values(is_system_dark=False)\n        )","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/theme/set_system_theme.py#L43-L79","documentation":"Raised by SetSystemThemeCommand.validate() when ThemeDAO.find_by_id(theme_id) returns None. The command that sets a theme as the system default first resolves the theme by primary key; a missing row aborts before any DB write with ThemeNotFoundError (HTTP 404-mapped, surfaced as 'Theme not found.'","triggerScenarios":"Calling the theme API endpoint that sets the system default theme (e.g. PUT/POST on /api/v1/theme/... set-system-default route) with a theme_id that does not exist in the theme table, or with an ID of a theme deleted by another user between listing and calling.","commonSituations":"Stale frontend state after a theme was deleted; passing an internal integer ID from an outdated cache; test fixtures that reference seeded theme IDs that no longer exist after a DB reset or migration.","solutions":["Verify the theme exists first: GET the theme by the same ID before issuing the set-system-default call.","If the ID came from a cached list, refresh the theme list and retry with the current ID.","If this happens in tests, re-seed or re-create themes in setup so the referenced ID is valid.","Check for concurrent deletion: query the theme table for the ID and re-create the theme if it was removed."],"exampleFix":"# before\nSetSystemThemeCommand(theme_id=99).run()  # 99 does not exist\n\n# after\nfrom superset.daos.theme import ThemeDAO\nif ThemeDAO.find_by_id(99) is None:\n    raise ValueError(\"theme 99 missing; refresh theme list\")\nSetSystemThemeCommand(theme_id=99).run()","handlingStrategy":"validation","validationCode":"from superset.daos.theme import ThemeDAO\nif ThemeDAO.find_by_id(theme_id) is None:\n    raise LookupError(f\"theme {theme_id} not found\")","typeGuard":null,"tryCatchPattern":"from superset.commands.theme.exceptions import ThemeNotFoundError\ntry:\n    SetSystemThemeCommand(theme_id).run()\nexcept ThemeNotFoundError:\n    reload_themes_and_retry_once()","preventionTips":["Fetch theme by ID before issuing set-default commands","Never cache theme integer IDs across sessions"],"tags":["theme","not-found","validation","backend"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}