{"record":{"id":"5f6a09286af1c0fe","repo":"apache/superset","slug":"cannot-delete-theme-that-is-set-as-system-default","errorCode":null,"errorMessage":"Cannot delete theme that is set as system default or dark theme.","messagePattern":"Cannot delete theme that is set as system default or dark theme\\.","errorType":"exception","errorClass":"SystemThemeInUseError","httpStatus":500,"severity":"error","filePath":"superset/commands/theme/delete.py","lineNumber":64,"sourceCode":"\n        # Dissociate dashboards from themes before deleting\n        self._dissociate_dashboards()\n\n        ThemeDAO.delete(self._models)\n\n    def validate(self) -> None:\n        # Validate/populate model exists\n        self._models = ThemeDAO.find_by_ids(self._model_ids)\n        if not self._models or len(self._models) != len(self._model_ids):\n            raise ThemeNotFoundError()\n\n        # Check if any of the themes are system themes\n        for theme in self._models:\n            if theme.is_system:\n                raise SystemThemeProtectedError()\n            # Check if theme is in use as system default or dark\n            if theme.is_system_default or theme.is_system_dark:\n                raise SystemThemeInUseError()\n\n        # Check for dashboard usage\n        self._dashboard_usage = self._get_dashboard_usage()\n\n    def _dissociate_dashboards(self) -> None:\n        \"\"\"Dissociate dashboards from themes before deletion.\"\"\"\n        from superset.models.dashboard import Dashboard\n\n        theme_ids = [theme.id for theme in self._models or []]\n        if not theme_ids:\n            return\n\n        # Get count of affected dashboards for logging\n        affected_count = (\n            db.session.query(Dashboard)\n            .filter(Dashboard.theme_id.in_(theme_ids))\n            .count()\n        )","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/theme/delete.py#L46-L82","documentation":"SystemThemeInUseError raised when a theme in the delete set is currently referenced as the deployment's system default theme or system dark theme (is_system_default / is_system_dark flags on the row). Deleting the active default would leave the deployment without a fallback theme, so validate() rejects the bulk delete before _dissociate_dashboards or ThemeDAO.delete run.","triggerScenarios":"Deleting the theme currently selected in configuration as THEME.DEFAULT / dark variant, or any theme row whose is_system_default/is_system_dark flags are set, as part of a bulk delete.","commonSituations":"Rebranding flows that delete the old corporate theme while it is still the configured default; cleanup scripts unaware of the config linkage.","solutions":["Switch the system default/dark theme configuration to another theme first, then delete the old one.","Clear is_system_default/is_system_dark on the row (via admin theme settings) before deletion if it is genuinely no longer the default.","Exclude in-use themes from bulk delete payloads programmatically."],"exampleFix":"# before (theme 5 is configured default)\nDeleteThemesCommand([5]).run()  # SystemThemeInUseError\n# after\nset_system_default_theme(other_theme_id)\nDeleteThemesCommand([5]).run()","handlingStrategy":"validation","validationCode":"in_use = {t.id for t in themes if t.is_system_default or t.is_system_dark}\npayload = [i for i in ids if i not in in_use]","typeGuard":"def is_theme_in_use(theme) -> bool:\n    return bool(theme.is_system_default or theme.is_system_dark)","tryCatchPattern":"try:\n    DeleteThemesCommand(ids).run()\nexcept SystemThemeInUseError:\n    reassign_system_defaults()\n    retry_once()","preventionTips":["Reassign the system default/dark theme before deleting the current one.","Check the is_system_default/is_system_dark flags in delete flows.","Rebranding runbooks: switch config first, delete second."],"tags":["themes","configuration","protected-resources"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}