Skip to content

Commit

Permalink
Explicitly request a large number of results from BB grading API
Browse files Browse the repository at this point in the history
Due to a bug in Blackboard (see: #5839)
we fetch results for all students and just pick the right one.

We didn't implement pagination together with that change so we are
missing students that are part of the course but are present in other
pages.

For now will just request a large number of results and alert when we
still hit the pagination limit.
  • Loading branch information
marcospri committed Sep 19, 2024
1 parent 53d5804 commit 7717adc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lms/services/lti_grading/_v13.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def read_result(self, grading_id) -> GradingResult:
if self._product_family == Family.BLACKBOARD:
# There's currently a bug in Blackboard's LTIA implementation.
# Using the user filter in the request removes the comment field in the response's body.
# So we'll remove the parameter and will search for the right student in the response.
del params["user_id"]
# We explicitly add a big limit parameter to try to fetch as many results as possible
# without having to fetch more pages (which we have not implemented)
params["limit"] = 1000

try:
response = self._ltia_service.request(
Expand All @@ -67,6 +71,11 @@ def read_result(self, grading_id) -> GradingResult:
# Due to the bug mentioned above we didn't use the API filtering by user for blackboard.
# We'll filter ourselves here instead.
results = [result for result in results if result["userId"] == grading_id]
if response.links.get("next"):
# We want to be notified if we are leaving results unfetched and likely start following these links
LOG.error(
"Blackboard grading reading result, container with paginated results"
)

if not results:
return result
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/lms/services/lti_grading/_v13_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_read_result_blackboard(
misc_plugin,
lti_registration,
):
ltia_http_service.request.return_value = Mock(links={"next": None})
ltia_http_service.request.return_value.json.return_value = blackboard_response
blackboard_svc.line_item_url = "https://lms.com/lineitems?param=1"

Expand All @@ -91,7 +92,7 @@ def test_read_result_blackboard(
"GET",
"https://lms.com/lineitems/results?param=1",
scopes=blackboard_svc.LTIA_SCOPES,
params={},
params={"limit": 1000},
headers={"Accept": "application/vnd.ims.lis.v2.resultcontainer+json"},
)
assert (
Expand All @@ -104,6 +105,17 @@ def test_read_result_blackboard(
)
assert result.comment == misc_plugin.clean_lms_grading_comment.return_value

def test_read_result_blackboard_pagination_limit(
self, blackboard_svc, ltia_http_service, blackboard_response, caplog
):
ltia_http_service.request.return_value = Mock(links={"next": sentinel.next})
ltia_http_service.request.return_value.json.return_value = blackboard_response

result = blackboard_svc.read_result(sentinel.user_id)

assert "paginated" in caplog.text
assert result

def test_get_score_maximum(self, svc, ltia_http_service, lti_registration):
ltia_http_service.request.return_value.json.return_value = [
{"scoreMaximum": sentinel.score_max, "id": svc.line_item_url},
Expand Down

0 comments on commit 7717adc

Please sign in to comment.