{"record":{"id":"ff5e8bdbd697ff39","repo":"invoke-ai/InvokeAI","slug":"user-user-id-not-found","errorCode":null,"errorMessage":"User {user_id} not found","messagePattern":"User (.+?) not found","errorType":"exception","errorClass":"ValueError","httpStatus":404,"severity":"error","filePath":"invokeai/app/services/users/users_default.py","lineNumber":191,"sourceCode":"                SELECT {_USER_DTO_COLUMNS}\n                FROM users\n                WHERE email = ?\n                \"\"\",\n                (email,),\n            )\n            row = cursor.fetchone()\n\n        if row is None:\n            return None\n\n        return _user_dto_from_row(row)\n\n    def update(self, user_id: str, changes: UserUpdateRequest, strict_password_checking: bool = True) -> UserDTO:\n        \"\"\"Update user.\"\"\"\n        # Check if user exists\n        user = self.get(user_id)\n        if user is None:\n            raise ValueError(f\"User {user_id} not found\")\n\n        self._assert_system_user_protected(\n            user_id, is_admin=changes.is_admin, is_active=changes.is_active, password=changes.password\n        )\n\n        # Validate password if provided\n        if changes.password is not None:\n            if strict_password_checking:\n                is_valid, error_msg = validate_password_strength(changes.password)\n                if not is_valid:\n                    raise ValueError(error_msg)\n            elif not changes.password:\n                raise ValueError(\"Password cannot be empty\")\n\n        # Build update query dynamically based on provided fields\n        updates: list[str] = []\n        params: list[str | bool | int] = []\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/users/users_default.py#L173-L209","documentation":"UserService.update raises ValueError when the given user_id does not exist in the users table; self.get(user_id) returned None before any changes were applied. It is a pre-condition check, not a write failure, and it fires identically for deleted, never-created, or mistyped IDs.","triggerScenarios":"Calling UserService.update(user_id, changes) (e.g. UserUpdateRequest changing display_name, password, is_admin, or is_active) with a user_id that is not present in the database - deleted user, typo/whitespace in the ID, or an ID from another database/environment.","commonSituations":"Tests and admin scripts reusing stale user IDs after a DB reset; clients caching user IDs that were later deleted; passing a UUID-style string from a different InvokeAI installation; trailing whitespace in a copied ID.","solutions":["Verify the ID with users.get(user_id) (or get_by_email) before updating; it returns None for missing users.","Re-fetch the current user list (get_many) to obtain a fresh, valid user_id after DB resets or deletions.","Strip/normalize the user_id string; if it came from an API payload, validate it server-side.","If the user should exist, create them first (create/create_admin) before updating."],"exampleFix":"// before\nusers.update(user_id, UserUpdateRequest(display_name='New Name'))\n// after\nif users.get(user_id) is None:\n    raise LookupError(f'No user {user_id!r}; pick one from users.get_many()')\nusers.update(user_id, UserUpdateRequest(display_name='New Name'))","handlingStrategy":"validation","validationCode":"user = users.get(user_id)\nif user is None:\n    raise LookupError(f'User {user_id!r} does not exist')\n# safe to update now","typeGuard":null,"tryCatchPattern":"try:\n    users.update(user_id, changes)\nexcept ValueError as e:\n    if str(e) == f'User {user_id} not found':\n        logger.warning('Skipping update for missing user %s', user_id)\n    else:\n        raise","preventionTips":["Always fetch the user (get/get_by_email) before mutating; check for None","Refresh cached user IDs after DB resets, fixtures, or deletions","Strip and validate user_id strings received from clients or config","Centralize existence checks in a helper so all admin scripts benefit"],"tags":["valueerror","not-found","user-management","lookup"],"backgroundTag":"resource-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}