fix: handle DatabaseType enum conversion in config management
Fix type conversion issues when handling DatabaseType enum values in configuration loading and GUI updates. - config/loader.py: Handle both enum and string types for DB_TYPE - config/schema.py: Properly convert db_type when it's already a string - gui/config_manager.py: Add Enum type conversion with validation in set_nested_value These changes prevent AttributeError when accessing .value on string values and ensure proper type handling throughout the configuration system. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,8 +94,20 @@ class ConfigManager:
|
||||
for k in keys[:-1]:
|
||||
obj = getattr(obj, k)
|
||||
|
||||
# 获取目标字段信息用于类型转换
|
||||
target_field = keys[-1]
|
||||
field_type = type(getattr(obj, target_field))
|
||||
|
||||
# 如果是字符串且目标字段是枚举类型,进行转换
|
||||
if isinstance(value, str) and hasattr(field_type, "__members__"): # 它是一个 Enum
|
||||
try:
|
||||
value = field_type(value)
|
||||
except ValueError:
|
||||
# 无效的枚举值,保持当前值不变
|
||||
value = getattr(obj, target_field)
|
||||
|
||||
# 设置最终值
|
||||
setattr(obj, keys[-1], value)
|
||||
setattr(obj, target_field, value)
|
||||
|
||||
def reset_to_defaults(self) -> None:
|
||||
"""重置为默认配置"""
|
||||
|
||||
Reference in New Issue
Block a user