From 0da69dd3f6b0e2a8e012ee3ce03cd4204e547e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AD=E9=92=B0=E9=92=B0?= <672178818@qq.com> Date: Mon, 31 Aug 2026 09:33:15 +0800 Subject: [PATCH] fix: ensure config directory exists before mkstemp in _write_config_snapshot (#9856) 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 b3b9c4a99..912620722 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -296,6 +296,10 @@ class AstrBotConfig(dict): 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)}.",