Skip to content

[Bug] Second user registration relies on implicit db.commit(), causing raw 500 on conflict #228

@jigangz

Description

@jigangz

Pre-checks

Deployment Method

Source code

Steps to Reproduce

  1. Complete initial setup (first admin user created successfully)
  2. Register a second user at /api/auth/register
  3. If any database constraint is violated (e.g. duplicate email), the response is a raw 500 error instead of a proper JSON error

Expected vs Actual Behavior

Expected: A 409 Conflict JSON response with a clear error message.

Actual: A raw 500 Internal Server Error with no JSON body. The frontend shows a generic "Request failed" message.

Root Cause

In backend/app/api/auth.py, db.commit() is only called explicitly in the first-user (admin) registration path. For subsequent users, the commit is deferred to the get_db() dependency cleanup. If that deferred commit hits an IntegrityError, FastAPI cannot catch it and returns a raw 500.

Logs / Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions