修复数据库管理器类型安全问题
- 在DatabaseManager.database属性中添加None检查,确保返回类型安全 - 避免MySQLDatabase | None类型与MySQLDatabase类型不匹配的问题 - 增强数据库连接初始化失败时的错误处理 - 确保get_database()函数始终返回有效的MySQLDatabase实例
This commit is contained in:
parent
3131f3089d
commit
05c1cc0a6d
@ -54,6 +54,11 @@ class DatabaseManager:
|
|||||||
"""获取数据库连接实例"""
|
"""获取数据库连接实例"""
|
||||||
if self._database is None:
|
if self._database is None:
|
||||||
self._create_connection()
|
self._create_connection()
|
||||||
|
|
||||||
|
# 确保数据库连接已创建
|
||||||
|
if self._database is None:
|
||||||
|
raise RuntimeError("数据库连接初始化失败")
|
||||||
|
|
||||||
return self._database
|
return self._database
|
||||||
|
|
||||||
def _create_connection(self):
|
def _create_connection(self):
|
||||||
|
|||||||
@ -8,8 +8,7 @@ from database_manager import BaseModel, get_database
|
|||||||
|
|
||||||
# 导入公共配置
|
# 导入公共配置
|
||||||
from common import (
|
from common import (
|
||||||
normalize_stock_code, get_table_name, LOG_PREFIXES,
|
normalize_stock_code, get_table_name, LOG_PREFIXES
|
||||||
KLINE_COLUMNS, FIELD_LIMITS
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@ -48,7 +48,7 @@ def test_kline_viewer():
|
|||||||
if 'ma' in indicators:
|
if 'ma' in indicators:
|
||||||
print(f" 计算了 {len(indicators['ma'])} 条移动平均线")
|
print(f" 计算了 {len(indicators['ma'])} 条移动平均线")
|
||||||
if 'macd' in indicators:
|
if 'macd' in indicators:
|
||||||
print(f" MACD指标计算完成")
|
print(" MACD指标计算完成")
|
||||||
|
|
||||||
print(f"{LOG_PREFIXES['SUCCESS']} 所有测试通过!新的双层架构工作正常")
|
print(f"{LOG_PREFIXES['SUCCESS']} 所有测试通过!新的双层架构工作正常")
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user