Skip to content

Commit

Permalink
Ignore known error codes from the rostering services
Browse files Browse the repository at this point in the history
We'll tackle this individually as we gather more information are able to
reproduce and fix them.
  • Loading branch information
marcospri committed Sep 4, 2024
1 parent 0a271c2 commit f78f8ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 49 deletions.
23 changes: 6 additions & 17 deletions lms/services/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,13 @@ def fetch_assignment_roster(self, assignment: Assignment) -> None:
resource_link_id=assignment.lti_v13_resource_link_id,
)
except ExternalRequestError as err:
if (
err.response_body
and (
# Error message from Canvas
"Requested ResourceLink bound to unexpected external tool"
in err.response_body
)
# In cases for which we have different assignment IDs
and assignment.resource_link_id != assignment.lti_v13_resource_link_id
if err.response_body and (
"Requested ResourceLink bound to unexpected external tool" # Canvas, unknown reason
in err.response_body
):
# The LMS (Canvas) doesn't seem to be able to link our tool to this assignment
# Try the same call but with the LTI1.1 assignment identifier.
LOG.info("Try to fetch roster with the LTI1.1 identifier")
roster = self._lti_names_roles_service.get_context_memberships(
lti_registration,
lms_course.lti_context_memberships_url,
resource_link_id=assignment.resource_link_id,
)
LOG.error("Fetching assignment roster failed: %s", err.response_body)
# We ignore this type of error, just stop here.
return
else:
raise

Expand Down
38 changes: 6 additions & 32 deletions tests/unit/lms/services/roster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,45 +128,19 @@ def test_fetch_assignment_roster(
assert not roster[3].active

def test_fetch_assignment_roster_retries_with_lti_v11_id(
self,
svc,
lti_names_roles_service,
lti_v13_application_instance,
assignment,
names_and_roles_roster_response,
lti_role_service,
self, svc, lti_names_roles_service, assignment
):
lti_role_service.get_roles.return_value = [
factories.LTIRole(value="ROLE1"),
factories.LTIRole(value="ROLE2"),
]

lti_names_roles_service.get_context_memberships.side_effect = [
lti_names_roles_service.get_context_memberships.side_effect = (
ExternalRequestError(
response=Mock(
text="Requested ResourceLink bound to unexpected external tool"
)
),
names_and_roles_roster_response,
]

svc.fetch_assignment_roster(assignment)

lti_names_roles_service.get_context_memberships.assert_has_calls(
[
call(
lti_v13_application_instance.lti_registration,
"SERVICE_URL",
assignment.lti_v13_resource_link_id,
),
call(
lti_v13_application_instance.lti_registration,
"SERVICE_URL",
assignment.resource_link_id,
),
]
)
)

# Method finishes without re-raising the exception
assert not svc.fetch_assignment_roster(assignment)

def test_fetch_assignment_roster_raises_external_request_error(
self, svc, lti_names_roles_service, assignment
):
Expand Down

0 comments on commit f78f8ad

Please sign in to comment.