Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parameters to Submission.edit when using Submission.upload_file #554

Open
madsobitsoe opened this issue Sep 15, 2022 · 2 comments

Comments

@madsobitsoe
Copy link

When using canvasapi.submission.Submission.upload_file, the file is first uploaded, then attached to a comment with canvasapi.submission.Submission.edit.

Is it possible to extend upload_file such that it accepts an optional **kwargs, that can be passed to edit in case the upload succeeded?

This would allow for uploading a file setting the text_comment parameter for uploaded files, as well as setting the group_comment parameter when uploading files as comments on a submission as a grader.

@bennettscience
Copy link
Contributor

I see the potential value, but the rest of the library only accepts **kwargs on routes that also accept arguments. The file upload flow doesn't accept any parameters, so adding that seems like it would be stepping outside the patterns used everywhere else.

When a file is uploaded successfully, it returns the attachment data that has to be posted to the submission endpoint anyways. The comment goes on the submission, not on the file.

@madsobitsoe
Copy link
Author

I might be misreading/misunderstanding the code, but bear with me.
In this line of Submission.upload_comment:

self.edit(comment={"file_ids": [response[1]["id"]]})

Submission.edit is called.

If I understand it correctly, this will create a new comment on the submission, with the attached file.

Can/Should I then use the returned response-object to obtain a reference to the posted submission comment, so I can edit the parameters of the comment after it has been posted?
(for example for setting the [group_comment] parameter on the comment, when uploading files as feedback when grading).

cnuahs added a commit to cnuahs/canvasapi that referenced this issue Apr 23, 2024
Lots of weirdness around how uploading files to a submission works.
(see for example ucfopen#496 ucfopen#554 ucfopen#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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants