24
24
from django .utils .text import format_lazy
25
25
from django .utils .translation import gettext_lazy as _
26
26
from django_colortag .models import ColorTag
27
+ from requests .exceptions import HTTPError
27
28
28
29
from apps .models import BaseTab , BasePlugin
29
30
from authorization .models import JWTAccessible
@@ -935,6 +936,11 @@ def enroll_from_sis(self) -> Tuple[int, int]:
935
936
delcount = 0
936
937
try :
937
938
participants = sis .get_participants (self .sis_id )
939
+ except HTTPError as exc :
940
+ code = exc .response .status_code
941
+ # pylint: disable-next=logging-fstring-interpolation
942
+ logger .exception (f"{ self } : Error { code } when getting participants from SIS." )
943
+ return - 1 , - 1
938
944
except Exception :
939
945
# pylint: disable-next=logging-fstring-interpolation
940
946
logger .exception (f"{ self } : Error in getting participants from SIS." )
@@ -954,16 +960,18 @@ def enroll_from_sis(self) -> Tuple[int, int]:
954
960
# yet logged in to A+, then the user profile does not exist yet.
955
961
pass
956
962
957
- # Remove SIS-enrolled students who are not anymore in SIS participants,
958
- # for example, because they have first enrolled in SIS, but then
959
- # unenrolled themselves.
960
- students = self .all_students .filter (enrollment__from_sis = True )
961
- to_remove = students .exclude (student_id__in = participants )
962
- qs = Enrollment .objects .filter (user_profile__in = to_remove , course_instance = self )
963
- qs .update (status = Enrollment .ENROLLMENT_STATUS .REMOVED )
964
- for e in qs :
965
- invalidate_content (Enrollment , e )
966
- delcount += 1
963
+ # Ignore empty participants list caused by a rare SIS API gateway malfunction
964
+ if participants :
965
+ # Remove SIS-enrolled students who are not anymore in SIS participants,
966
+ # for example, because they have first enrolled in SIS, but then
967
+ # unenrolled themselves.
968
+ students = self .all_students .filter (enrollment__from_sis = True )
969
+ to_remove = students .exclude (student_id__in = participants )
970
+ qs = Enrollment .objects .filter (user_profile__in = to_remove , course_instance = self )
971
+ qs .update (status = Enrollment .ENROLLMENT_STATUS .REMOVED )
972
+ for e in qs :
973
+ invalidate_content (Enrollment , e )
974
+ delcount += 1
967
975
968
976
# pylint: disable-next=logging-fstring-interpolation
969
977
logger .info (f"{ self } : enrolled { addcount } , removed { delcount } students based on SIS" )
0 commit comments