Skip to content

fix: persist username changes in account settings (PATCH /auth/me)#213

Open
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/username-save-205
Open

fix: persist username changes in account settings (PATCH /auth/me)#213
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/username-save-205

Conversation

@jigangz
Copy link
Copy Markdown

@jigangz jigangz commented Mar 27, 2026

Summary

Fix username changes not being saved in the Account Settings modal.

Problem

The PATCH /auth/me endpoint used db.flush() instead of db.commit(). While flush() writes to the transaction buffer, the actual commit depends on the get_db() dependency cleanup which runs after the response is sent. Combined with expire_on_commit=False, this can result in:

  • Changes not being persisted reliably
  • The returned user object missing server-side updates (updated_at)

Changes

  • Replace db.flush() with db.commit() for explicit persistence
  • Add db.refresh(current_user) to ensure the returned object reflects committed state

Testing

  1. Navigate to Account Settings
  2. Change username → click Save → username persists after page reload
  3. Change email → click Save → email persists
  4. Change display name → click Save → display name persists
  5. Try duplicate username → returns 409 error correctly

Fixes #205

The endpoint used db.flush() which writes to the DB transaction buffer
but relies on the dependency cleanup to commit. If the response
serialization happens before the commit, or if the session's
expire_on_commit=False prevents refresh, the returned user object
may not reflect the persisted state.

This changes to explicit commit() + refresh() to ensure:
1. Changes are persisted immediately
2. The returned UserOut reflects the committed state
3. Server-side fields (updated_at) are properly populated

Fixes dataelement#205
@jigangz jigangz marked this pull request as ready for review March 27, 2026 05:20
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] Username change cannot be saved in Account Settings

1 participant