From 1998a0e3831afab51b5bd8c3c30a5ba94a0bb7c1 Mon Sep 17 00:00:00 2001 From: Pasi Sarolahti Date: Mon, 29 May 2023 19:19:17 +0300 Subject: [PATCH] Fix the removed counts in SIS logging SIS logging incorrectly counted earlier removed students as removed on every updated. Now it counts only those participants who were not removed earlier. --- course/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/course/models.py b/course/models.py index dc9977b3f..0becff550 100644 --- a/course/models.py +++ b/course/models.py @@ -964,11 +964,13 @@ def enroll_from_sis(self) -> Tuple[int, int]: # unenrolled themselves. students = self.all_students.filter(enrollment__from_sis=True) to_remove = students.exclude(student_id__in=participants) - qs = Enrollment.objects.filter(user_profile__in=to_remove, course_instance=self) - qs.update(status=Enrollment.ENROLLMENT_STATUS.REMOVED) + qs = (Enrollment.objects + .filter(user_profile__in=to_remove, course_instance=self) + .exclude(status=Enrollment.ENROLLMENT_STATUS.REMOVED) + ) for e in qs: invalidate_content(Enrollment, e) - delcount += 1 + delcount = qs.update(status=Enrollment.ENROLLMENT_STATUS.REMOVED) else: logger.warning("%s: Received an empty participants list from SIS.", self) return 0, 0