{"record":{"id":"69ca5eafd2bfb407","repo":"apache/superset","slug":"theme-doesn-t-exist-and-user-doesn-t-have-permissi","errorCode":null,"errorMessage":"Theme doesn't exist and user doesn't have permission to create themes","messagePattern":"Theme doesn't exist and user doesn't have permission to create themes","errorType":"exception","errorClass":"ThemeImportError","httpStatus":500,"severity":"error","filePath":"superset/commands/theme/import_themes.py","lineNumber":49,"sourceCode":"\nlogger = logging.getLogger(__name__)\n\n\ndef import_theme(config: dict[str, Any], overwrite: bool = False) -> \"Theme | None\":\n    \"\"\"Import a single theme from config dictionary\"\"\"\n    from superset import db, security_manager\n    from superset.models.core import Theme\n    from superset.utils.core import get_user\n\n    can_write = security_manager.can_access(\"can_write\", \"Theme\")\n    existing = db.session.query(Theme).filter_by(uuid=config[\"uuid\"]).first()\n\n    if existing:\n        if not overwrite or not can_write:\n            return existing\n        config[\"id\"] = existing.id\n    elif not can_write:\n        raise ThemeImportError(\n            \"Theme doesn't exist and user doesn't have permission to create themes\"\n        )\n\n    # Convert json_data from dict to string if needed\n    if isinstance(config.get(\"json_data\"), dict):\n        config[\"json_data\"] = json.dumps(config[\"json_data\"])\n\n    # Create or update theme\n    theme = Theme.import_from_dict(config, recursive=False)\n    if theme.id is None:\n        db.session.flush()\n\n    # Add current user as owner if creating new theme\n    if not existing and (user := get_user()):\n        theme.changed_by = user\n        theme.created_by = user\n\n    return theme","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/theme/import_themes.py#L31-L67","documentation":"ThemeImportError with message 'Theme doesn't exist and user doesn't have permission to create themes' raised in the theme import helper: the imported config's uuid matches no existing Theme row (so this would be a create, not an overwrite) and the importing user lacks the can_write permission on ThemeView. Import only creates themes for users holding write access; read-only importers may solely overwrite existing themes (and even that requires can_write with overwrite=True).","triggerScenarios":"Running an import (POST import endpoint or REST import with a theme payload) as a user without can_write on Theme, where the payload's config['uuid'] does not match any existing theme.","commonSituations":"Non-admin or custom role performing theme migration between environments where the theme does not yet exist; import bundles containing themes in addition to dashboards, executed by users with only dashboard import rights.","solutions":["Grant the importing user can_write on Theme (or perform the import as Admin).","Pre-create the theme in the target environment so the import resolves to an overwrite path.","Remove theme entries from the import bundle if the user only needs dashboard import."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"can_write = security_manager.can_access(\"can_write\", \"Theme\")\nexisting = db.session.query(Theme).filter_by(uuid=config[\"uuid\"]).first()\nif not existing and not can_write:\n    raise PermissionError(\"import would create a theme; can_write on Theme required\")","typeGuard":null,"tryCatchPattern":"try:\n    import_themes(configs, overwrite=True)\nexcept ThemeImportError as ex:\n    if \"permission to create\" in str(ex.message):\n        escalate_to_admin_or_grant_can_write()","preventionTips":["Grant can_write on Theme to users who import new themes.","Pre-create themes in target environments so imports overwrite rather than create.","Strip theme entries from bundles for users with dashboard-only import rights."],"tags":["themes","import-export","permissions","rbac"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}