ValueError("Invalid group") in query_userinfo causes 500 instead of proper 4xx response
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
When a user (including superadmin) creates a session via CLI without being a member of the target project group, the server returns a 500 Internal Server Error instead of a descriptive 4xx error.
Root Cause:
query_userinfo() in manager/utils.py:224 raises plain ValueError("Invalid group") instead of a BackendAIError subclass (e.g., InvalidAPIParameters). Since ValueError does not inherit from BackendAIError, the exception middleware converts it to a 500.
Additionally, in manager/services/session/service.py, the query_userinfo() call (line 501) is located outside the try/except block (line 512), so even the catch-all handler does not catch it.
How to Reproduce:
1. Log in as superadmin via CLI
2. Ensure the superadmin is NOT a member of the "default" project group
3. Run: backend.ai session create (without --group)
4. Observe 500 Internal Server Error
Expected Behavior:
A 400-level error with a clear message such as "You are not a member of the specified project group" should be returned.
Files to Fix:
- src/ai/backend/manager/utils.py:224 — Change ValueError("Invalid group") to InvalidAPIParameters (or similar BackendAIError subclass). Also applies to other ValueError raises in the same function (lines 138, 175, 197, 210).
- src/ai/backend/manager/services/session/service.py — Move query_userinfo() call inside the try/except block, or handle its exceptions explicitly.
JIRA Issue: BA-5697
Contributor guide
Assessment
This issue has not been assessed yet.