Skip to content

Commit

Permalink
fix: catch exception (openedx#1866)
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenk authored Jun 22, 2022
1 parent 0dab24e commit 4eec889
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions openassessment/xblock/team_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ def teams_configuration_service(self):
def get_team_for_anonymous_user(self, anonymous_user_id):
"""
For course_id associated with this ORA block, returns the provided user's
CourseTeam, or None if the user is not a member of a team in this course.
CourseTeam, or None if the user is not a member of a team in this course or
if the teams service is unavailable.
Raises:
- NoSuchServiceError if the teams service is unavailable
- ObjectDoesNotExist if the user associated with `anonymous_user_id`
can not be found
"""
user = self.get_real_user(anonymous_user_id)
if not user:
logger.error('%s: User lookup for anonymous_user_id %s failed', self.location, anonymous_user_id)
raise ObjectDoesNotExist()
team = self.teams_service.get_team(user, self.course_id, self.selected_teamset_id)
try:
team = self.teams_service.get_team(user, self.course_id, self.selected_teamset_id)
except NoSuchServiceError:
logger.debug("%s %s [AU-660]", self.location, anonymous_user_id)
return None
return team

@cached_property
Expand All @@ -70,7 +74,6 @@ def team(self):
For the user and course_id associated with this ORA block, returns the user's
CourseTeam, or None if the user is not a member of a team in this course.
Raises:
- NoSuchServiceError if the teams service is unavailable
- ObjectDoesNotExist if the user associated with `anonymous_user_id`
can not be found
"""
Expand Down
3 changes: 1 addition & 2 deletions openassessment/xblock/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def test_team_no_user_found(self):

def test_team_no_teams_service(self):
block = MockBlock(has_teams_service=False)
with self.assertRaises(NoSuchServiceError):
_ = block.team
self.assertIsNone(block.team)

def test_team_no_user(self):
block = MockBlock(has_team=False)
Expand Down

0 comments on commit 4eec889

Please sign in to comment.