Skip to content

fix: handle registration commit errors with proper JSON response#224

Open
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/second-user-registration-error
Open

fix: handle registration commit errors with proper JSON response#224
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/second-user-registration-error

Conversation

@jigangz
Copy link
Copy Markdown

@jigangz jigangz commented Mar 29, 2026

Summary

Fix "Request failed" error when registering the second user account.

Root cause

The /auth/register endpoint only called db.commit() explicitly for the first user (platform admin). For subsequent registrations, the commit was deferred to the get_db() dependency's finally block. If that deferred commit hit an IntegrityError (or any other database error), FastAPI returned a raw 500 response with no JSON body — which the frontend displayed as a generic "Request failed" message.

Fix

  • Add explicit db.commit() for all registration paths
  • Catch IntegrityError and return a proper HTTP 409 JSON response with a descriptive error message
  • Remove redundant intermediate db.flush() calls — the single commit handles both User and Participant creation atomically
  • Unify first-user and non-first-user commit paths

Changes

  • backend/app/api/auth.py: unified commit + IntegrityError handling

Checklist

  • Tested locally
  • No unrelated changes included

Fixes #228

…aelement#223)

When registering the second user (non-admin), the register endpoint
relied on get_db()'s implicit commit after the function returned. If
that deferred commit hit a database constraint violation (IntegrityError),
FastAPI returned a raw 500 response with no JSON body. The frontend
parsed this as 'Request failed' with no useful error message.

Changes:
- Add explicit db.commit() for all registration paths (not just first user)
- Catch IntegrityError and return a proper 409 JSON response
- Remove redundant intermediate db.flush() calls — the single commit
  handles both User and Participant creation atomically
- First-user path: commit now happens before seed_default_agents() as
  before, just unified with the non-first-user path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant