From 4d3aa0faf35545607d78fc6e7687490dc06825e1 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:48:02 +0800 Subject: [PATCH] fix(config): update in-memory setting only on env update --- app/core/config.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index eca5c9c3..1c9b6ec0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -360,15 +360,19 @@ class Settings(BaseSettings, ConfigModel): try: field = self.__fields__[key] + original_value = getattr(self, key) if field.name == "API_TOKEN": - converted_value, needs_update = self.validate_api_token(value, getattr(self, key)) + converted_value, needs_update = self.validate_api_token(value, original_value) else: - converted_value, needs_update = self.generic_type_converter(value, getattr(self, key), field.type_, + converted_value, needs_update = self.generic_type_converter(value, original_value, field.type_, field.default, key) # 如果没有抛出异常,则统一使用 converted_value 进行更新 if needs_update or str(value) != str(converted_value): - setattr(self, key, converted_value) - return self.update_env_config(field, value, converted_value) + success, message = self.update_env_config(field, original_value, converted_value) + # 仅成功更新配置时,才更新内存 + if success: + setattr(self, key, converted_value) + return success, message return True, "" except Exception as e: return False, str(e)