{"record":{"id":"5a3389d81b1d8315","repo":"infiniflow/ragflow","slug":"user-username-not-found-5a3389","errorCode":null,"errorMessage":"User '{username}' not found","messagePattern":"User '(.+?)' not found","errorType":"http","errorClass":"UserNotFoundError","httpStatus":404,"severity":"error","filePath":"admin/server/services.py","lineNumber":104,"sourceCode":"        # Check if the email address is already used\n        if UserService.query(email=username):\n            raise UserAlreadyExistsError(username)\n        # Construct user info data\n        user_info_dict = {\n            \"email\": username,\n            \"nickname\": \"\",  # ask user to edit it manually in settings.\n            \"password\": decrypt(password),\n            \"login_channel\": \"password\",\n            \"is_superuser\": role == \"admin\",\n        }\n        return create_new_user(user_info_dict)\n\n    @staticmethod\n    def delete_user(username):\n        # use email to delete\n        user_list = UserService.query_user_by_email(username)\n        if not user_list:\n            raise UserNotFoundError(username)\n        if len(user_list) > 1:\n            raise AdminException(f\"Exist more than 1 user: {username}!\")\n        usr = user_list[0]\n        return delete_user_data(usr.id)\n\n    @staticmethod\n    def update_user_password(username, new_password) -> str:\n        # use email to find user. check exist and unique.\n        user_list = UserService.query_user_by_email(username)\n        if not user_list:\n            raise UserNotFoundError(username)\n        elif len(user_list) > 1:\n            raise AdminException(f\"Exist more than 1 user: {username}!\")\n        # check new_password different from old.\n        usr = user_list[0]\n        psw = decrypt(new_password)\n        # SSO-provisioned users (OIDC/OAuth) have no local password (usr.password is None):\n        # skip the equality check, which would otherwise crash inside werkzeug's split().","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/admin/server/services.py#L86-L122","documentation":"UserNotFoundError (HTTP 404) raised by UserMgr.delete_user (admin/server/services.py:104) when UserService.query_user_by_email(username) returns an empty list. Deletion resolves the account solely by email; no match means nothing to delete. Defined in admin/server/exceptions.py:8.","triggerScenarios":"DELETE admin API call with a typo'd or unknown email; deleting a user already removed; passing a nickname/user-id where an email is required; wrong database/environment so the account does not exist there.","commonSituations":"Re-running a teardown script after it already succeeded; case-mismatch in the email (lookup is by exact email string); environments drifting between staging and prod; users provisioned under a different email by SSO.","solutions":["Verify the email exists first: query with UserService.query_user_by_email(username) or UserMgr.get_user_details(username).","Make teardown idempotent: catch UserNotFoundError and treat it as already-deleted.","Copy the exact email from get_all_users() output rather than typing it.","Confirm you are connected to the intended database/instance."],"exampleFix":"# before\nUserMgr.delete_user('user@example.com')  # 404\n\n# after\nfrom admin.server.exceptions import UserNotFoundError\ntry:\n    UserMgr.delete_user('user@example.com')\nexcept UserNotFoundError:\n    print('already gone')","handlingStrategy":"try-catch","validationCode":"from api.db.services import UserService\n\ndef can_delete(email: str) -> bool:\n    users = UserService.query_user_by_email(email.strip())\n    return len(users) == 1","typeGuard":null,"tryCatchPattern":"from admin.server.exceptions import UserNotFoundError\ntry:\n    UserMgr.delete_user(email)\nexcept UserNotFoundError:\n    pass  # already gone; idempotent teardown","preventionTips":["Copy emails from get_all_users() output instead of typing them.","Order offboarding steps: export/delete resources first, delete user last, and make reruns tolerant of 404.","Catch UserNotFoundError in automation and log it as a no-op."],"tags":["not-found","user-management","admin-api","delete"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}