From f6259c468fdf26961d08c633480de269ab62b544 Mon Sep 17 00:00:00 2001 From: LeonWehrhahn Date: Thu, 30 Jan 2025 15:32:06 +0100 Subject: [PATCH] Remove lms_url from DBStructuredGradingCriterion and update related queries --- athena/athena/models/db_structured_grading_criterion.py | 1 - athena/athena/schemas/grading_criterion.py | 1 - .../athena/storage/structured_grading_criterion_storage.py | 7 +++---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/athena/athena/models/db_structured_grading_criterion.py b/athena/athena/models/db_structured_grading_criterion.py index b0679ae70..624a8268a 100644 --- a/athena/athena/models/db_structured_grading_criterion.py +++ b/athena/athena/models/db_structured_grading_criterion.py @@ -12,6 +12,5 @@ class DBStructuredGradingCriterion(Base): exercise_id = Column(BigIntegerWithAutoincrement, ForeignKey("exercise.id", ondelete="CASCADE"), index=True, unique=True) # Only one cached instruction per exercise instructions_hash = Column(String, nullable=False) structured_grading_criterion = Column(JSON, nullable=False) - lms_url = Column(String, nullable=False) exercise = relationship("DBExercise", back_populates="structured_grading_criterion") \ No newline at end of file diff --git a/athena/athena/schemas/grading_criterion.py b/athena/athena/schemas/grading_criterion.py index f13e23768..91b6c69ba 100644 --- a/athena/athena/schemas/grading_criterion.py +++ b/athena/athena/schemas/grading_criterion.py @@ -8,7 +8,6 @@ class StructuredGradingInstruction(Schema, ABC): """Part of a grading criterion (called "GradingInstruction" in LMS).""" - id: int = Field(example=1) credits: float = Field(description="The number of credits assigned for this feedback.", example=1.0) grading_scale: str = Field(description="The grading outcome for this instruction.", example="Weak example", default="") diff --git a/athena/athena/storage/structured_grading_criterion_storage.py b/athena/athena/storage/structured_grading_criterion_storage.py index 06c3ebdd3..b1123df2f 100644 --- a/athena/athena/storage/structured_grading_criterion_storage.py +++ b/athena/athena/storage/structured_grading_criterion_storage.py @@ -8,8 +8,9 @@ def get_structured_grading_criterion(exercise_id: int, current_hash: Optional[str] = None) -> Optional[StructuredGradingCriterion]: lms_url = get_lms_url() with get_db() as db: - cache_entry = db.query(DBStructuredGradingCriterion).filter_by( - exercise_id=exercise_id, lms_url=lms_url + cache_entry = db.query(DBStructuredGradingCriterion).filter( + DBStructuredGradingCriterion.exercise_id == exercise_id, + DBStructuredGradingCriterion.exercise.has(lms_url=lms_url) ).first() if cache_entry is not None and (current_hash is None or cache_entry.instructions_hash == current_hash): # type: ignore return StructuredGradingCriterion.parse_obj(cache_entry.structured_grading_criterion) @@ -18,12 +19,10 @@ def get_structured_grading_criterion(exercise_id: int, current_hash: Optional[st def store_structured_grading_criterion( exercise_id: int, hash: str, structured_instructions: StructuredGradingCriterion ): - lms_url = get_lms_url() with get_db() as db: db.merge( DBStructuredGradingCriterion( exercise_id=exercise_id, - lms_url=lms_url, instructions_hash=hash, structured_grading_criterion=structured_instructions.dict(), )