instructure / canvas-lms

The open LMS by Instructure, Inc.
https://github.com/instructure/canvas-lms/wiki
GNU Affero General Public License v3.0
5.41k stars 2.42k forks source link

`Question.points_possible` field is always 1 or 0 when part of a `QuizGroup` #2308

Open dave-doty opened 5 months ago

dave-doty commented 5 months ago

Summary:

The points_possible field of QuizQuestion is incorrect. (when part of a QuizGroup; see comment below) In my case the question is worth 20 points, but points_possible is 1.

Steps to reproduce:

I discovered this through the canvasapi Python package. However, this appears to be a bug in the Canvas API itself, not the Python package. In debugging I checked the underlying response JSON from the GET request that canvasapi executes (https://canvas.instructure.com/doc/api/quiz_questions.html#method.quizzes/quiz_questions.show, https://github.com/ucfopen/canvasapi/blob/02d42cba3b0fd22e780ac0a5e904ea84fbc0b58d/canvasapi/quiz.py#L244) and see that the JSON field points_possible is 1 for a question, even though I assigned that question to be 20 points.

  1. Create a Canvas quiz.
  2. Add a FileUpload question (not sure if that's relevant, but it's the type of question I have) and make it worth 20 points.
  3. Install the canvasapi Python package with pip install canvasapi.
  4. Execute the following Python code. (Or do its equivalent requests through the Canvas API directly, without installing the canvasapi package, but this seems simpler.)
    API_URL = 'https://canvas.ucdavis.edu'   # change to your canvas root URL
    API_KEY = '...'                          # change to your private API KEY
    course_id = 123456                       # change to your course ID
    quiz_id = 7890                           # change to your quiz ID
    question_id = 1234                       # change to your question ID
    canvas = canvasapi.Canvas(API_URL, API_KEY)
    course = canvas.get_course(course_id)
    quiz = course.get_quiz(quiz_id)
    question = quiz.get_question(question_id)
    print(question.points_possible)

Expected behavior:

It should print 20.

Actual behavior:

It prints 1. (or sometimes 0... I couldn't tell the pattern here, but I tried this a few times and it was always 1 or 0 for every question on every quiz)

Additional notes:

I would directly share my Sandbox course where I'm seeing this happen (https://canvas.ucdavis.edu/courses/166766) so you could skip some of these steps, but I don't know how to grant a private access token only to that Sandbox course, without also giving it permission to access my real courses.

I could not figure out how to determine the question_id from the Canvas webpage (it doesn't show up in a URL the way the course ID and the quiz ID do); in my case I am processing a list of QuizSubmission objects named submission, and I use the field submission.question_id to determine the question ID. So you may have to do something like that in order to determine the question ID for the question you added in Step 2.

dave-doty commented 4 months ago

Ah, I think I figured out the problem. I accidentally neglected to include this detail, but the question is part of a Question Group. I see that the associated QuizGroup object has a field question_points, which has the correct value of 20.0.

I'm not sure if it's a bug that the Question object itself has the field points_possible with the wrong value. It seems as though it should have the same value as question_points in the group it is a part of.