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
| Name | Type | Description |
|---|---|---|
| session | Session | The active SQLAlchemy or SQLModel database session used to persist changes. |
| db_user | User | The existing user record retrieved from the database that will be modified. |
| user_in | UserUpdate | A Pydantic model containing the partial updates to apply, such as a new email or password. |
Returns
| Type | Description |
|---|---|
User | The updated user database object after changes have been committed and refreshed from the session. |