canvasapi icon indicating copy to clipboard operation
canvasapi copied to clipboard

QuizSubmission update_score_and_comments doesn't seem to work

Open breed opened this issue 2 years ago • 3 comments

Describe the bug

when i call update_score_and_comments(fudge_points=points) on a quiz submission, i get the error "missing required key :quiz_submissions" back. looking through the code it doesn't seem like the data being sent to the canvas server matches the required format: https://canvas.instructure.com/doc/api/quiz_submissions.html#method.quizzes/quiz_submissions_api.update

To Reproduce

     for s in quiz.get_submissions():
         s.update_score_and_comments(fudge_points=9)

Expected behavior

the fudge_points get set to 9

Environment information

  • Python version (python --version) Python 3.10.6
  • CanvasAPI version (pip show canvasapi) Name: canvasapi Version: 3.0.0

Additional context

Add any other context about the problem here.

breed avatar Apr 04 '23 06:04 breed

Two things: the endpoint expects a list of objects and you also need to include the required attempt param to apply the fudge score to. This will work:

for s in quiz.get_submissions():
    updated = [
        {
            'attempt': 1,
            'fudge_points': 9
        }
    ]
    s.update_score_and_comments(quiz_submissions=updated)

bennettscience avatar Apr 04 '23 12:04 bennettscience

dang, i though i had tried that! thank you for the super quick response. that works thank you!

it seems a little off to have to do the wrapping in the quiz_submissions, since that is always needed, and to add the attempt, since that is in s (the QuizSubmission object). i've put up #602 to make this a little nicer while still preserving legacy behavior.

breed avatar Apr 04 '23 16:04 breed

Yeah, there's a few places the API expects a list or dict without really being specific - the only way you can tell is based on how they note the parameters in the docs. It bit me in the but a lot when I first started.

I like the idea of wrapping for people as the default in the library...curious what @Thetwam will say.

Glad I could help 👍

bennettscience avatar Apr 04 '23 16:04 bennettscience