diff --git a/common/tabby_config.py b/common/tabby_config.py index a1f258b..13b8718 100644 --- a/common/tabby_config.py +++ b/common/tabby_config.py @@ -2,7 +2,7 @@ import yaml import pathlib from loguru import logger from typing import Optional -from os import getenv, replace +from os import getenv from common.utils import unwrap, merge_dicts from common.config_models import TabbyConfigModel, generate_config_file @@ -98,11 +98,15 @@ class TabbyConfig(TabbyConfigModel): new_cfg = TabbyConfigModel.model_validate(cfg) try: - replace(config_path, f"{config_path}.bak") + config_path.rename(f"{config_path}.bak") generate_config_file(model=new_cfg, filename=config_path) except Exception as e: logger.error(f"Auto migration failed: {e}") + # Restore the old config + config_path.unlink(missing_ok=True) + pathlib.Path(f"{config_path}.bak").rename(config_path) + return unwrap(cfg, {}) def _from_args(self, args: dict): @@ -118,9 +122,6 @@ class TabbyConfig(TabbyConfigModel): for key in TabbyConfigModel.model_fields.keys(): override = args.get(key) if override: - if key == "logging": - # Strip the "log_" prefix from logging keys if present - override = {k.replace("log_", ""): v for k, v in override.items()} config[key] = override return config diff --git a/common/utils.py b/common/utils.py index 77958ce..f8b4671 100644 --- a/common/utils.py +++ b/common/utils.py @@ -1,7 +1,7 @@ """Common utility functions""" from types import NoneType -from typing import Optional, Type, Union, get_args, get_origin +from typing import Type, Union, get_args, get_origin def unwrap(wrapped, default=None):