From 40bac665b30c1d9f43fceacdfa9a1aba8bfd491e Mon Sep 17 00:00:00 2001 From: Shaun Cloherty Date: Tue, 23 Apr 2024 10:45:31 +1000 Subject: [PATCH] Remove call to Submission.edit() in Submission.upload_comment(). Lots of weirdness around how uploading files to a submission works. (see for example #496 #554 #631). This isn't really a fix for any of those. This is just a quick hack to make it work for my use case. At present, a call to Submission.upload_comment() to upload a file to attach to a comment, includes an implicit call to Submission.edit() that creates an empty comment (i.e, no text) on the submission, or, attached the file to any previous comment. This doesn't seem to fit with the description in the Canvas API documentation and is never what you actually want. This change removes that implicit call to .edit(). To comment on a submission and attache a file, first call .upload_comment() to upload the file, and then call .edit() including your comment text, grade etc. as well as the file id returned by .upload_comment(). --- canvasapi/submission.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/canvasapi/submission.py b/canvasapi/submission.py index f2d738c0..d6f79f75 100644 --- a/canvasapi/submission.py +++ b/canvasapi/submission.py @@ -176,8 +176,8 @@ def upload_comment(self, file: FileOrPathLike, **kwargs): **kwargs ).start() - if response[0]: - self.edit(comment={"file_ids": [response[1]["id"]]}) + # if response[0]: + # self.edit(comment={"file_ids": [response[1]["id"]]}) return response