fix(db): refresh user after role update to avoid DetachedInstanceError#6638
Merged
Conversation
…'Failed to update user')
Member
|
hey @mvanhorn , thanks for adding this PR. mind signing CLA? also - are you the founder of Lyft? :O |
Adjust the incidents/alerts filtering e2e tests for the DetachedInstanceError fix; remaining lint findings reproduce on HEAD and are pre-existing.
Contributor
|
🚂 Fantastic work @mvanhorn! Your very first PR to keep has been merged! 🎉🥳 You've just taken your first step into open-source, and we couldn't be happier to have you onboard. 🙌 For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩💻👨💻 |
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
Under DB authentication, editing a user's role in Settings fails with "Failed to update user".
update_user_rolecommitted the role change but never refreshed the ORM object, so the returnedUserwas detached with expired attributes and building the response raisedDetachedInstanceError-> HTTP 500. This mirrors the session handling its siblingupdate_user_passwordalready uses.Background
roma55443 reported the "Failed to update user" error in #4296. A later 501 "Updating users is not supported by this identity manager" was a separate symptom already fixed by #6609 (which added
DbIdentityManager.update_user); the role-change 500 is the live remaining defect. Inkeep/api/core/db.py,update_user_roleruns insidewith Session(engine)(defaultexpire_on_commit=True) and returnsuseraftersession.commit(), but unlikeupdate_user_passwordin the same file it never callssession.refresh(user). Once the session block closes, the object is detached and its attributes are expired, soupdate_userraisesDetachedInstanceErrorwhen it readsupdated_user.usernameto build the response.The fix adds
session.refresh(user)after the role-changing commit and an earlyreturn Nonefor a missing user, matchingupdate_user_passwordexactly. Added regression tests totests/test_change_password.pycovering a changed role, an unchanged role, and a missing user, alongside the existing DB-auth update tests.Closes #4296