{"record":{"id":"5e5979a2c9e17151","repo":"invoke-ai/InvokeAI","slug":"str-e-5e5979","errorCode":null,"errorMessage":"str(e)","messagePattern":"str\\(e\\)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"invokeai/app/api/routers/auth.py","lineNumber":399,"sourceCode":"\n    # Check if any admin exists\n    if user_service.has_admin():\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"Administrator account already configured\",\n        )\n\n    # Create admin user - this will validate password strength\n    try:\n        user_data = UserCreateRequest(\n            email=request.email,\n            display_name=request.display_name,\n            password=request.password,\n            is_admin=True,\n        )\n        user = user_service.create_admin(user_data, strict_password_checking=config.strict_password_checking)\n    except ValueError as e:\n        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) from e\n\n    return SetupResponse(success=True, user=user)\n\n\n# ---------------------------------------------------------------------------\n# User management models\n# ---------------------------------------------------------------------------\n\n_PASSWORD_ALPHABET = string.ascii_letters + string.digits + string.punctuation\n\n\nclass AdminUserCreateRequest(BaseModel):\n    \"\"\"Request body for admin to create a new user.\"\"\"\n\n    email: str = Field(description=\"User email address\")\n    display_name: str | None = Field(default=None, description=\"Display name\")\n    password: str = Field(description=\"User password\")\n    is_admin: bool = Field(default=False, description=\"Whether user should have admin privileges\")","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/auth.py#L381-L417","documentation":"HTTP 400 raised when `user_service.create_admin(...)` throws ValueError during setup_admin (auth.py:399). The service validates the admin fields and — when `config.strict_password_checking` is true — password strength; any ValueError (bad username, weak password, duplicate name) is forwarded verbatim as the exception detail via `str(e)`.","triggerScenarios":"POST /auth/setup whose payload contains a weak password while strict_password_checking is enabled, an invalid/empty username or display_name, or a username that already exists in the users table.","commonSituations":"Automated provisioning scripts POSTing a weak default password (e.g. 'admin123') against a strict-password config; duplicate setup calls where the second request reuses an already-taken username; locale/whitespace issues in display_name.","solutions":["Read the `detail` string of the 400 response — it is the service ValueError and states the exact validation failure (e.g. weak password).","Use a password satisfying the configured strength rules (length/complexity) or relax strict_password_checking in invokeai.yaml for dev environments.","Choose a unique username; check existing users before calling setup.","Validate the SetupRequest payload client-side (non-empty username/display_name, password length) before POSTing."],"exampleFix":"// before: fixed weak password in provisioning script\nconst body = {username:'admin', display_name:'Admin', password:'admin123'};\n// after: strong generated password\nconst body = {username:'admin', display_name:'Admin', password: crypto.randomBytes(16).toString('base64url') + '!Aa1'};","handlingStrategy":"validation","validationCode":"function validateSetupPayload(p) {\n  const errs = [];\n  if (!p.username || !p.username.trim()) errs.push('username required');\n  if (!p.display_name || !p.display_name.trim()) errs.push('display_name required');\n  if (!p.password || p.password.length < 12) errs.push('password too weak (min 12 chars)');\n  return errs; // empty array => safe to POST /auth/setup\n}","typeGuard":"function isSetupRequest(v) {\n  return typeof v === 'object' && v !== null &&\n    typeof v.username === 'string' && v.username.length > 0 &&\n    typeof v.display_name === 'string' &&\n    typeof v.password === 'string' && v.password.length >= 12;\n}","tryCatchPattern":"try {\n  await setupAdmin(body);\n} catch (e) {\n  if (e.status === 400) {\n    console.error('Setup rejected by service:', e.detail); // exact ValueError\n  } else throw e;\n}","preventionTips":["Generate strong passwords programmatically for bootstrap accounts","Check username uniqueness before setup","Verify strict_password_checking setting in invokeai.yaml and match its policy client-side","Never hardcode credentials in provisioning scripts"],"tags":["http-400","validation","auth","password-policy"],"backgroundTag":"validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}