From 97cc6656150380836c76e47bdae3a76c61b7aa5a Mon Sep 17 00:00:00 2001 From: xiaoyuyu6420 <93528429+xiaoyuyu6420@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:14:48 +0800 Subject: [PATCH] fix: ensure config directory exists before mkstemp in _write_config_snapshot AstrBotConfig._write_config_snapshot calls tempfile.mkstemp(dir=directory) without verifying the directory exists. When a config profile is created for the first time (e.g. create_conf instantiates AstrBotConfig with a brand-new path), __init__ calls save_config before the directory is guaranteed to exist, and mkstemp raises FileNotFoundError. Add os.makedirs(directory, exist_ok=True) before mkstemp. This is the standard defensive pattern for atomic-write helpers. Fixes three intermittently-failing dashboard tests: - test_t2i_set_active_template_syncs_all_configs - test_t2i_reset_default_template_syncs_all_configs - test_t2i_update_active_template_reloads_all_schedulers Closes #9855. --- astrbot/core/config/astrbot_config.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/astrbot/core/config/astrbot_config.py b/astrbot/core/config/astrbot_config.py index 44030672b7..85032ee824 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -287,6 +287,10 @@ def _write_config_snapshot( Whether the snapshot replaced the current configuration file. """ directory = os.path.dirname(os.path.abspath(self.config_path)) or "." + # The directory may not exist yet when a config profile is created for + # the first time (e.g. `create_conf` instantiates AstrBotConfig with a + # brand-new path). mkstemp would raise FileNotFoundError otherwise. + os.makedirs(directory, exist_ok=True) fd, temp_path = tempfile.mkstemp( dir=directory, prefix=f".{os.path.basename(self.config_path)}.",