Skip to content

Canvas Quiz create_report generate exceptions #671

@scott-yj-yang

Description

@scott-yj-yang

Describe the bug

When the quiz does not have a new entries, and a new student report is requested, canvasapi throws exception.

To Reproduce

Steps to reproduce the behavior:

  • Generate quiz report when there is no new entries.
{
	"name": "Conflict",
	"message": "{\"status\":\"conflict\",\"message\":\"report is already being generated\"}",
	"stack": "---------------------------------------------------------------------------
Conflict                                  Traceback (most recent call last)
Input In [6], in <cell line: 1>()
----> 1 github_usernames = cg.fetch_username_from_quiz(quiz_id=185628)

File ~/anaconda3/envs/CanvasGroupy/lib/python3.10/site-packages/CanvasGroupy/canvas.py:237, in CanvasGroup.fetch_username_from_quiz(self, quiz_id, col_index)
    233 if self.verbosity != 0:
    234     print(f\"Quiz: {bcolors.OKGREEN+quiz.title+bcolors.ENDC} \"
    235           f\"fetch! \
Generating Student Analaysis...\"
    236          )
--> 237 report = quiz.create_report(\"student_analysis\")
    238 progress_url = report.progress_url
    239 completed = False

File ~/anaconda3/envs/CanvasGroupy/lib/python3.10/site-packages/canvasapi/quiz.py:141, in Quiz.create_report(self, report_type, **kwargs)
    135     raise ValueError(
    136         \"Param `report_type` must be a either 'student_analysis' or 'item_analysis'\"
    137     )
    139 kwargs[\"quiz_report\"] = {\"report_type\": report_type}
--> 141 response = self._requester.request(
    142     \"POST\",
    143     \"courses/{}/quizzes/{}/reports\".format(self.course_id, self.id),
    144     _kwargs=combine_kwargs(**kwargs),
    145 )
    147 response_json = response.json()
    148 response_json.update({\"course_id\": self.course_id})

File ~/anaconda3/envs/CanvasGroupy/lib/python3.10/site-packages/canvasapi/requester.py:257, in Requester.request(self, method, endpoint, headers, use_auth, _url, _kwargs, json, **kwargs)
    255     raise ResourceDoesNotExist(\"Not Found\")
    256 elif response.status_code == 409:
--> 257     raise Conflict(response.text)
    258 elif response.status_code == 422:
    259     raise UnprocessableEntity(response.text)

Conflict: {\"status\":\"conflict\",\"message\":\"report is already being generated\"}"

Expected behavior

From the doc:

Create and return a new report for this quiz. If a previously generated report matches the arguments and is still current (i.e. there have been no new submissions), it will be returned.

Environment information

  • Python version (python --3.10.9)
  • CanvasAPI version (pip show canvasapi) 3.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions