fix: handle registration commit errors with proper JSON response#224
Open
jigangz wants to merge 1 commit intodataelement:mainfrom
Open
fix: handle registration commit errors with proper JSON response#224jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz wants to merge 1 commit intodataelement:mainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix "Request failed" error when registering the second user account.
Root cause
The
/auth/registerendpoint only calleddb.commit()explicitly for the first user (platform admin). For subsequent registrations, the commit was deferred to theget_db()dependency's finally block. If that deferred commit hit anIntegrityError(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
db.commit()for all registration pathsIntegrityErrorand return a proper HTTP 409 JSON response with a descriptive error messagedb.flush()calls — the single commit handles both User and Participant creation atomicallyChanges
backend/app/api/auth.py: unified commit + IntegrityError handlingChecklist
Fixes #228