fix(settings): properly save and clear configuration values
Backend:
- Replace dict mutation with dict replacement to fix SQLAlchemy JSON
mutation tracking issue (config.config = {**config.config, **update_data})
Frontend:
- Send explicit null values instead of undefined so fields can be cleared
- Update UserConfigUpdate interface to accept null values
This commit is contained in:
@@ -112,7 +112,8 @@ async def update_user_config(
|
|||||||
# Merge updates
|
# Merge updates
|
||||||
update_data = data.model_dump(exclude_unset=True)
|
update_data = data.model_dump(exclude_unset=True)
|
||||||
logger.info("Updating user config for user %s: %s", user_id, update_data)
|
logger.info("Updating user config for user %s: %s", user_id, update_data)
|
||||||
config.config.update(update_data)
|
# SQLAlchemy JSON doesn't track dict mutations, so we replace the whole dict
|
||||||
|
config.config = {**config.config, **update_data}
|
||||||
|
|
||||||
await session.commit()
|
await session.commit()
|
||||||
await session.refresh(config)
|
await session.refresh(config)
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ export interface UserConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UserConfigUpdate {
|
export interface UserConfigUpdate {
|
||||||
default_editor?: string;
|
default_editor?: string | null;
|
||||||
theme?: string;
|
theme?: string | null;
|
||||||
git_user_name?: string;
|
git_user_name?: string | null;
|
||||||
git_user_email?: string;
|
git_user_email?: string | null;
|
||||||
last_session_id?: string;
|
last_session_id?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getUserConfig = async (): Promise<UserConfig> => {
|
export const getUserConfig = async (): Promise<UserConfig> => {
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ export const SettingsPage = () => {
|
|||||||
try {
|
try {
|
||||||
const update: UserConfigUpdate = {
|
const update: UserConfigUpdate = {
|
||||||
theme: config.theme,
|
theme: config.theme,
|
||||||
default_editor: config.default_editor ?? undefined,
|
default_editor: config.default_editor,
|
||||||
git_user_name: config.git_user_name ?? undefined,
|
git_user_name: config.git_user_name,
|
||||||
git_user_email: config.git_user_email ?? undefined,
|
git_user_email: config.git_user_email,
|
||||||
};
|
};
|
||||||
console.log("Sending update:", update);
|
console.log("Sending update:", update);
|
||||||
const updated = await updateUserConfig(update);
|
const updated = await updateUserConfig(update);
|
||||||
|
|||||||
Reference in New Issue
Block a user