Skip to content

[BUG] PUT /profile endpoint bypasses username uniqueness validation and returns IntegrityError #673

Description

@sujitha-kotyada

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

  1. Create two user accounts:

    • User A with username alice
    • User B with username bob
  2. Authenticate as User B.

  3. Send a PUT request to:

/api/v1/profile
  1. Update the username to:
alice
  1. Submit the request.

  2. 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

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Labels

bugSomething isn't workinggssocGirlScript Summer of Code 2026 issue/PR

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions