fix: ExamService.start_exam返回ID避免懒加载
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
修改start_exam返回exam.id而不是整个Exam对象, 彻底避免SQLAlchemy异步会话的懒加载问题
This commit is contained in:
@@ -20,7 +20,7 @@ class ExamService:
|
||||
@staticmethod
|
||||
async def start_exam(
|
||||
db: AsyncSession, user_id: int, course_id: int, question_count: int = 10
|
||||
) -> Exam:
|
||||
) -> int:
|
||||
"""
|
||||
开始考试
|
||||
|
||||
@@ -31,7 +31,7 @@ class ExamService:
|
||||
question_count: 题目数量
|
||||
|
||||
Returns:
|
||||
Exam: 考试实例
|
||||
int: 考试ID
|
||||
"""
|
||||
# 检查课程是否存在
|
||||
course = await db.get(Course, course_id)
|
||||
@@ -93,8 +93,10 @@ class ExamService:
|
||||
db.add(exam)
|
||||
await db.commit()
|
||||
await db.refresh(exam)
|
||||
|
||||
return exam
|
||||
|
||||
# 返回exam.id而不是整个对象,避免懒加载问题
|
||||
exam_id = exam.id
|
||||
return exam_id
|
||||
|
||||
@staticmethod
|
||||
async def submit_exam(
|
||||
|
||||
Reference in New Issue
Block a user