Skip to content

Commit

Permalink
Ensure mastery log end_timestamp is consistently updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Nov 20, 2024
1 parent 2a05933 commit 7d5f3e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 10 additions & 12 deletions kolibri/core/logger/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,13 @@ def _update_and_return_mastery_log_id(
mastery_level=context["mastery_level"],
summarylog_id=summarylog_id,
)
update_fields = tuple()
if time_spent_delta:
masterylog.time_spent = (
masterylog.time_spent or 0
) + time_spent_delta
update_fields += ("time_spent",)
masterylog.end_timestamp = end_timestamp
update_fields = self._update_content_log(
masterylog,
end_timestamp,
{"time_spent_delta": time_spent_delta},
masterylog=True,
)
if complete and not masterylog.complete:
masterylog.complete = True
masterylog.completion_timestamp = end_timestamp
Expand All @@ -627,10 +628,7 @@ def _update_and_return_mastery_log_id(
self._process_masterylog_completed_notification(masterylog, context)
else:
self._check_quiz_log_permissions(masterylog)
if update_fields:
masterylog.save(
update_fields=update_fields + ("_morango_dirty_bit",)
)
masterylog.save(update_fields=update_fields)
return masterylog.id
except MasteryLog.DoesNotExist:
raise ValidationError(
Expand Down Expand Up @@ -798,7 +796,7 @@ def _normalize_progress(self, progress):
progress = ceil(progress * 1000) / float(1000)
return max(0, min(1.0, progress))

def _update_content_log(self, log, end_timestamp, validated_data):
def _update_content_log(self, log, end_timestamp, validated_data, masterylog=False):
update_fields = ("end_timestamp", "_morango_dirty_bit")

log.end_timestamp = end_timestamp
Expand All @@ -807,7 +805,7 @@ def _update_content_log(self, log, end_timestamp, validated_data):
log.progress = self._normalize_progress(
log.progress + validated_data["progress_delta"]
)
elif "progress" in validated_data:
elif not masterylog and "progress" in validated_data:
update_fields += ("progress",)
log.progress = self._normalize_progress(validated_data["progress"])
if "time_spent_delta" in validated_data:
Expand Down
4 changes: 4 additions & 0 deletions kolibri/core/logger/test/test_integrated_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,7 @@ def setUp(self):
mastery_criterion=mastery_model,
summarylog=self.summary_log,
start_timestamp=self.summary_log.start_timestamp,
end_timestamp=self.summary_log.start_timestamp,
user=self.user,
mastery_level=1,
)
Expand Down Expand Up @@ -2175,6 +2176,9 @@ def test_update_assessment_session_update_time_delta_succeeds(self):
self.assertEqual(response.status_code, 200)
self.mastery_log.refresh_from_db()
self.assertEqual(self.mastery_log.time_spent, 5)
self.assertNotEqual(
self.mastery_log.end_timestamp, self.mastery_log.start_timestamp
)

def test_update_assessment_session_create_attempt_in_lesson_succeeds(self):
lesson = create_assigned_lesson_for_user(self.user)
Expand Down

0 comments on commit 7d5f3e9

Please sign in to comment.