fix: 修复get_or_create返回值和MODEL_MAPPING

- 修复adapter.py db_save函数中get_or_create的元组解包
- 添加缺失的5个模型到MODEL_MAPPING: Videos, BotPersonalityInterests, BanUser, AntiInjectionStats, MonthlyPlan
- 修改test_retry_decorator使用exceptions参数支持通用Exception
- Stage 4-6测试现在100%通过 (26/26)
This commit is contained in:
Windpicker-owo
2025-11-01 14:09:17 +08:00
parent 148592686f
commit 3b42511f90

View File

@@ -17,6 +17,9 @@ from src.common.database.api import (
) )
from src.common.database.core.models import ( from src.common.database.core.models import (
ActionRecords, ActionRecords,
AntiInjectionStats,
BanUser,
BotPersonalityInterests,
CacheEntries, CacheEntries,
ChatStreams, ChatStreams,
Emoji, Emoji,
@@ -29,6 +32,7 @@ from src.common.database.core.models import (
MaiZoneScheduleStatus, MaiZoneScheduleStatus,
Memory, Memory,
Messages, Messages,
MonthlyPlan,
OnlineTime, OnlineTime,
PersonInfo, PersonInfo,
PermissionNodes, PermissionNodes,
@@ -36,6 +40,7 @@ from src.common.database.core.models import (
ThinkingLog, ThinkingLog,
UserPermissions, UserPermissions,
UserRelationships, UserRelationships,
Videos,
) )
from src.common.database.core.session import get_db_session from src.common.database.core.session import get_db_session
from src.common.logger import get_logger from src.common.logger import get_logger
@@ -52,6 +57,7 @@ MODEL_MAPPING = {
"Emoji": Emoji, "Emoji": Emoji,
"Images": Images, "Images": Images,
"ImageDescriptions": ImageDescriptions, "ImageDescriptions": ImageDescriptions,
"Videos": Videos,
"OnlineTime": OnlineTime, "OnlineTime": OnlineTime,
"Memory": Memory, "Memory": Memory,
"Expression": Expression, "Expression": Expression,
@@ -60,6 +66,10 @@ MODEL_MAPPING = {
"GraphEdges": GraphEdges, "GraphEdges": GraphEdges,
"Schedule": Schedule, "Schedule": Schedule,
"MaiZoneScheduleStatus": MaiZoneScheduleStatus, "MaiZoneScheduleStatus": MaiZoneScheduleStatus,
"BotPersonalityInterests": BotPersonalityInterests,
"BanUser": BanUser,
"AntiInjectionStats": AntiInjectionStats,
"MonthlyPlan": MonthlyPlan,
"CacheEntries": CacheEntries, "CacheEntries": CacheEntries,
"UserRelationships": UserRelationships, "UserRelationships": UserRelationships,
"PermissionNodes": PermissionNodes, "PermissionNodes": PermissionNodes,
@@ -294,8 +304,8 @@ async def db_save(
if not crud: if not crud:
crud = CRUDBase(model_class) crud = CRUDBase(model_class)
# 使用get_or_create # 使用get_or_create (返回tuple[T, bool])
instance = await crud.get_or_create( instance, created = await crud.get_or_create(
defaults=data, defaults=data,
**{key_field: key_value}, **{key_field: key_value},
) )