Description of the Bug
The PUT /profile endpoint updates user profile information without validating username uniqueness before committing changes to the database.
When a user attempts to change their username to one that already exists, the database unique constraint is triggered during commit, resulting in an unhandled IntegrityError and a 500 Internal Server Error.
This exposes a database-level failure to the client instead of returning a proper validation error.
As a result, profile updates can fail unexpectedly and produce inconsistent API behavior compared to other user-management endpoints that perform uniqueness checks before updating records.
Steps to Reproduce
-
Create two user accounts:
- User A with username
alice
- User B with username
bob
-
Authenticate as User B.
-
Send a PUT request to:
- Update the username to:
-
Submit the request.
-
Observe the API response and backend logs.
Expected Behavior
The endpoint should validate username uniqueness before committing changes.
If the requested username already exists, the API should return a user-friendly validation error such as:
HTTP 400 Bad Request
or
HTTP 409 Conflict
with an appropriate error message indicating that the username is already in use.
Screenshots / Logs
No response
Environment
OS: Windows 11 Browser: Google Chrome Backend: FastAPI Database: SQLite/PostgreSQL Python: 3.11
GSSoC '26
Description of the Bug
The
PUT /profileendpoint updates user profile information without validating username uniqueness before committing changes to the database.When a user attempts to change their username to one that already exists, the database unique constraint is triggered during commit, resulting in an unhandled
IntegrityErrorand a500 Internal Server Error.This exposes a database-level failure to the client instead of returning a proper validation error.
As a result, profile updates can fail unexpectedly and produce inconsistent API behavior compared to other user-management endpoints that perform uniqueness checks before updating records.
Steps to Reproduce
Create two user accounts:
alicebobAuthenticate as User B.
Send a PUT request to:
Submit the request.
Observe the API response and backend logs.
Expected Behavior
The endpoint should validate username uniqueness before committing changes.
If the requested username already exists, the API should return a user-friendly validation error such as:
HTTP 400 Bad Request
or
HTTP 409 Conflict
with an appropriate error message indicating that the username is already in use.
Screenshots / Logs
No response
Environment
OS: Windows 11 Browser: Google Chrome Backend: FastAPI Database: SQLite/PostgreSQL Python: 3.11
GSSoC '26