Skip to main content

update_user

Updates an existing user record in the database with provided data, including hashing the password if it is being changed. The function commits the changes to the database session and returns the refreshed user object.

def update_user(
session: Session,
db_user: User,
user_in: UserUpdate
) - > User

Updates an existing user's profile information in the database, including handling password hashing if a new password is provided.

Parameters

NameTypeDescription
sessionSessionThe active SQLAlchemy or SQLModel database session used to persist changes.
db_userUserThe existing user record retrieved from the database that will be modified.
user_inUserUpdateA Pydantic model containing the partial updates to apply, such as a new email or password.

Returns

TypeDescription
UserThe updated user database object after changes have been committed and refreshed from the session.