{"record":{"id":"74cbded3054451b0","repo":"apache/superset","slug":"subjects-are-invalid","errorCode":null,"errorMessage":"Subjects are invalid","messagePattern":"Subjects are invalid","errorType":"validation","errorClass":"SubjectsNotFoundValidationError","httpStatus":422,"severity":"error","filePath":"superset/commands/utils.py","lineNumber":95,"sourceCode":"            user_subject = get_user_subject(user_id)\n            return [user_subject] if user_subject else []\n        return []\n\n    if ensure_no_lockout and not security_manager.is_admin() and user_id:\n        user_subject = get_user_subject(user_id)\n        if (\n            user_subject\n            and user_subject.id not in subject_ids\n            and not _has_extra_editors_resolver()\n        ):\n            user_subject_ids = set(get_user_subject_ids(user_id))\n            if not (user_subject_ids & set(subject_ids)):\n                subjects.append(user_subject)\n\n    for sid in subject_ids:\n        subject = get_subject(sid)\n        if not subject:\n            raise SubjectsNotFoundValidationError(field_name)\n        subjects.append(subject)\n    return subjects\n\n\ndef compute_subject_list(\n    current_subjects: list[Subject] | None,\n    new_subject_ids: list[int] | None,\n    ensure_no_lockout: bool = False,\n    field_name: str = \"subjects\",\n) -> list[Subject]:\n    \"\"\"\n    Helper function for update commands, to properly handle the subjects list.\n    Preserve the previous configuration unless included in the update payload.\n\n    :param current_subjects: list of current subjects\n    :param new_subject_ids: list of new subject ids specified in the update payload\n    :param ensure_no_lockout: prevent non-admins from removing themselves\n    :param field_name: field name for validation errors","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/utils.py#L77-L113","documentation":"Raised in superset.commands.utils get_extra_subjects/subject resolution when a subject ID in owners/editors lists does not resolve via get_subject(). Superset validates every supplied subject ID (user or role) for chart/dashboard commands; any unknown ID raises SubjectsNotFoundValidationError ('Subjects are invalid').","triggerScenarios":"POST/PUT on chart or dashboard APIs with an 'owners' or (with feature-flagged extra editors) subjects list containing a user/role ID that does not exist — e.g. a deleted user, a wrong integer, or a role ID passed where a user ID was expected.","commonSituations":"Copying/duplicating dashboards via API with owner lists built from another environment; users removed by LDAP/SCIM sync but still referenced in payload; scripts transferring ownership to hardcoded IDs.","solutions":["Validate every subject ID against /api/v1/users or /api/v1/roles before submitting the payload.","Strip deleted users from owner lists; re-resolve owners by username instead of ID.","If the error appears during dashboard copy, update the tooling to filter owners to existing subjects first."],"exampleFix":"# before\npayload = {\"owners\": [1, 2, 99999]}  # 99999 deleted\n\n# after\nexisting = {u.id for u in UserDAO.find_users(payload_owners)}\npayload = {\"owners\": [i for i in payload_owners if i in existing]}","handlingStrategy":"validation","validationCode":"from superset.commands.utils import get_subject\nmissing = [sid for sid in subject_ids if get_subject(sid) is None]\nif missing:\n    raise ValueError(f\"unknown subject ids: {missing}\")","typeGuard":null,"tryCatchPattern":"from superset.commands.exceptions import SubjectsNotFoundValidationError\ntry:\n    cmd.run()\nexcept SubjectsNotFoundValidationError as e:\n    prune_bad_subjects_and_retry(e)","preventionTips":["Validate owner/role IDs against live users/roles APIs before submit","Filter owner lists at copy/import time"],"tags":["subjects","owners","validation","backend"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}