HKUDS/DeepTutor · error · ValueError
Role must be 'admin' or 'user'
Error message
Role must be 'admin' or 'user'
What it means
Pydantic ValidationError raised by RegisterRequest.role_valid in deeptutor/api/routers/auth.py:132 when a SetRoleRequest supplies a role string other than 'admin' or 'user'. The @field_validator('role') rejects any other value before the PUT /users/{username}/role endpoint runs; only the two allowed role names are accepted.
Solutions
- Send only 'admin' or 'user' in the role-change request
- Use a select control in the admin UI instead of free text
- Catch the 422 and display the allowed values
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at deeptutor/api/routers/auth.py:132 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/f3244e840a115465.
Report an issue: GitHub.
Appendix: source
Thrown at deeptutor/api/routers/auth.py:132
@field_validator("password")
@classmethod
def password_valid(cls, v: str) -> str:
if len(v) < 8:
raise ValueError("Password must be at least 8 characters")
return v
class SetRoleRequest(BaseModel):
"""Payload for the PUT /users/{username}/role endpoint."""
role: str
@field_validator("role")
@classmethod
def role_valid(cls, v: str) -> str:
if v not in ("admin", "user"):
raise ValueError("Role must be 'admin' or 'user'")
return v
class AuthStatusResponse(BaseModel):
"""Response body for the GET /status endpoint."""
enabled: bool
authenticated: bool
user_id: str | None = None
username: str | None = None
role: str | None = None
is_admin: bool = False
avatar: str = ""
class UserInfo(BaseModel):
"""Single user record returned by the GET /users and /profile endpoints."""
View on GitHub (pinned to 3e82f13042)