fix: preserve concurrent teacher decisions when model scoring fails
This commit is contained in:
@@ -387,13 +387,17 @@ def _run_project(batch_id, project_id, session_factory, client_factory, embedder
|
||||
except Exception as exc:
|
||||
db.rollback()
|
||||
score = db.scalar(select(CriterionScore).where(CriterionScore.batch_id == batch.id,
|
||||
CriterionScore.project_id == project.id, CriterionScore.criterion_id == criterion["criterion_id"]))
|
||||
CriterionScore.project_id == project.id, CriterionScore.criterion_id == criterion["criterion_id"])
|
||||
.with_for_update().execution_options(populate_existing=True))
|
||||
if not score:
|
||||
score = CriterionScore(batch_id=batch.id, project_id=project.id, criterion_id=criterion["criterion_id"])
|
||||
db.add(score)
|
||||
score.status, score.error = STATUS_FAILED, str(exc)[:500]
|
||||
db.commit()
|
||||
failures += 1
|
||||
# A teacher may have committed a decision while the request was in
|
||||
# flight. The exception path must honour it just like success does.
|
||||
if score.status != STATUS_REVIEWED and score.teacher_score is None:
|
||||
score.status, score.error = STATUS_FAILED, str(exc)[:500]
|
||||
db.commit()
|
||||
failures += 1
|
||||
db.execute(update(ScoringBatch).where(ScoringBatch.id == batch_id).values(progress_done=ScoringBatch.progress_done + 1))
|
||||
db.commit()
|
||||
return failures, reviews
|
||||
|
||||
Reference in New Issue
Block a user