20
20
from django .utils .text import format_lazy
21
21
from django .utils .translation import gettext_lazy as _
22
22
from django_colortag .models import ColorTag
23
+ from requests .exceptions import HTTPError
23
24
24
25
from apps .models import BaseTab , BasePlugin
25
26
from authorization .models import JWTAccessible
@@ -925,8 +926,11 @@ def enroll_from_sis(self) -> Tuple[int, int]:
925
926
delcount = 0
926
927
try :
927
928
participants = sis .get_participants (self .sis_id )
928
- except Exception as e :
929
- logger .exception (f"{ self } : Error in getting participants from SIS." )
929
+ except HTTPError as exc :
930
+ logger .exception ("%s: Error %d when getting participants from SIS." , self , exc .response .status_code )
931
+ return - 1 , - 1
932
+ except Exception :
933
+ logger .exception ("%s: Error in getting participants from SIS." , self )
930
934
return - 1 , - 1
931
935
932
936
from exercise .models import LearningObject
@@ -943,18 +947,23 @@ def enroll_from_sis(self) -> Tuple[int, int]:
943
947
# yet logged in to A+, then the user profile does not exist yet.
944
948
pass
945
949
946
- # Remove SIS-enrolled students who are not anymore in SIS participants,
947
- # for example, because they have first enrolled in SIS, but then
948
- # unenrolled themselves.
949
- students = self .all_students .filter (enrollment__from_sis = True )
950
- to_remove = students .exclude (student_id__in = participants )
951
- qs = Enrollment .objects .filter (user_profile__in = to_remove , course_instance = self )
952
- qs .update (status = Enrollment .ENROLLMENT_STATUS .REMOVED )
953
- for e in qs :
954
- invalidate_content (Enrollment , e )
955
- delcount += 1
956
-
957
- logger .info (f"{ self } : enrolled { addcount } , removed { delcount } students based on SIS" )
950
+ # Ignore empty participants list caused by a rare SIS API gateway malfunction
951
+ if participants :
952
+ # Remove SIS-enrolled students who are not anymore in SIS participants,
953
+ # for example, because they have first enrolled in SIS, but then
954
+ # unenrolled themselves.
955
+ students = self .all_students .filter (enrollment__from_sis = True )
956
+ to_remove = students .exclude (student_id__in = participants )
957
+ qs = Enrollment .objects .filter (user_profile__in = to_remove , course_instance = self )
958
+ qs .update (status = Enrollment .ENROLLMENT_STATUS .REMOVED )
959
+ for e in qs :
960
+ invalidate_content (Enrollment , e )
961
+ delcount += 1
962
+ else :
963
+ logger .warning ("%s: Received an empty participants list from SIS." , self )
964
+ return 0 , 0
965
+
966
+ logger .info ("%s: enrolled %d, removed %d students based on SIS" , self , addcount , delcount )
958
967
return addcount , delcount
959
968
960
969
def set_users_with_role (self , users , role , remove_others_with_role = False ):
0 commit comments