{"record":{"id":"b4b19adf056f32c4","repo":"HKUDS/DeepTutor","slug":"you-cannot-delete-your-own-account","errorCode":null,"errorMessage":"You cannot delete your own account","messagePattern":"You cannot delete your own account","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"deeptutor/api/routers/auth.py","lineNumber":829,"sourceCode":"        f\"(role={role!r})\"\n    )\n    return {\n        \"ok\": True,\n        \"user_id\": user_id,\n        \"username\": body.username,\n        \"role\": role,\n        \"is_admin\": role == \"admin\",\n    }\n\n\n@router.delete(\"/users/{username}\", status_code=status.HTTP_200_OK)\nasync def remove_user(\n    username: str,\n    current: TokenPayload = Depends(require_admin),\n) -> dict:\n    \"\"\"Delete a user. Admins cannot delete their own account.\"\"\"\n    if current and username == current.username:\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"You cannot delete your own account\",\n        )\n\n    # Capture the id before the record disappears so the avatar file can go too.\n    info = get_user_info(username)\n\n    removed = delete_user(username)\n    if not removed:\n        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=\"User not found\")\n\n    user_id = str(info.get(\"id\") or \"\") if info else \"\"\n    if user_id and _USER_ID_RE.match(user_id):\n        from deeptutor.multi_user.identity import delete_avatar_file\n\n        delete_avatar_file(user_id)\n\n    logger.info(f\"Admin '{current.username if current else 'local'}' deleted user '{username}'\")","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/auth.py#L811-L847","documentation":"Error \"You cannot delete your own account\" thrown in HKUDS/DeepTutor.","triggerScenarios":"Thrown at deeptutor/api/routers/auth.py:829 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}