dmitry-viskov / pylti1.3

LTI 1.3 Advantage Tool
MIT License
111 stars 60 forks source link

AssignmentsGradesService refactoring #101

Closed dmitry-viskov closed 1 year ago

dmitry-viskov commented 1 year ago

Related issues:

hmoffatt commented 1 year ago

This has broken put_grade in the case that you supply a LineItem that has an ID. I call find_or_create_lineitem myself because I need to control how it is matched.

My code says

        lineitem = LineItem() \
            .set_resource_link_id(resource_link_id) \
            .set_tag('score') \
            .set_label(resource_link_title) \
            .set_score_maximum(score.max_marks)

        lineitem = service.find_or_create_lineitem(lineitem, 'resource_link_id')
        service.put_grade(sc, lineitem)

Now this fails with the exception Can't find lineitem to put grade

This is because you are missing this line of code now from the old path that could create an item:

score_url = lineitem.get_id()

https://github.com/dmitry-viskov/pylti1.3/commit/f8e88046279055b23ff4ab5cc8b994a65fdd3735#diff-97daf71a186e6840c970de9dc18196b8b56751083509971cf18a693e45342432L73

hmoffatt commented 1 year ago

My solution to this is

diff --git a/pylti1p3/assignments_grades.py b/pylti1p3/assignments_grades.py
index a53ae81..12ab414 100644
--- a/pylti1p3/assignments_grades.py
+++ b/pylti1p3/assignments_grades.py
@@ -55,8 +55,9 @@ class AssignmentsGradesService(object):
         if not self.can_put_grade():
             raise LtiException("Can't put grade: Missing required scope")

-        if lineitem and not lineitem.get_id():
-            lineitem = self.find_or_create_lineitem(lineitem)
+        if lineitem:
+            if not lineitem.get_id():
+                lineitem = self.find_or_create_lineitem(lineitem)
             score_url = lineitem.get_id()
         elif not lineitem and self._service_data.get('lineitem'):
             score_url = self._service_data.get('lineitem')
hmoffatt commented 1 year ago

I've submitted #102 to fix this.