fix: 修复导入失败时的函数调用错误

- 在connect_database()中添加init_database和get_database的None检查
- 在_get_model_class()中添加create_stock_kline_model的None检查
- 当模块导入失败时提供清晰的错误信息,避免'NoneType' object is not callable错误
- 提高代码的健壮性和错误处理能力
This commit is contained in:
cuizhan 2025-07-24 11:34:36 +08:00
parent 0e2fa4a7b2
commit ff4491200f

View File

@ -92,6 +92,11 @@ class StockDataManager:
""" """
try: try:
if not self.is_connected: if not self.is_connected:
# 检查数据库函数是否可用
if init_database is None or get_database is None:
logger.error("❌ 数据库配置函数不可用,请检查database_config模块导入")
return False
# 初始化数据库 # 初始化数据库
if init_database(): if init_database():
self.database = get_database() self.database = get_database()
@ -135,6 +140,11 @@ class StockDataManager:
if model_key not in self.model_cache: if model_key not in self.model_cache:
try: try:
# 检查函数是否可用
if create_stock_kline_model is None:
logger.error("❌ create_stock_kline_model 函数不可用,请检查stock_models模块导入")
return None
# 创建模型类,使用标准化的股票代码 # 创建模型类,使用标准化的股票代码
model_class = create_stock_kline_model(normalized_code, period) model_class = create_stock_kline_model(normalized_code, period)
self.model_cache[model_key] = model_class self.model_cache[model_key] = model_class