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
Adds django storage backend for ORA2 file uploads. #1018
Adds django storage backend for ORA2 file uploads. #1018
Conversation
Thanks for the pull request, @pomegranited! It looks like you're a member of a company that does contract work for edX. If you're doing this work as part of a paid contract with edX, you should talk to edX about who will review this pull request. If this work is not part of a paid contract with edX, then you should ensure that there is an OSPR issue to track this work in JIRA, so that we don't lose track of your pull request. |
532e35f
to
a60c429
Compare
5128692
to
197ee00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had one request to add docstrings. Once tests pass, this is a 👍 from me!
- I tested this: I made a user on the sandbox and verified that file uploads work for ORA2 (I also verified the sandbox settings)
- I read through the code
-
I checked for accessibility issuesN/A - Includes documentation
def tearDown(self): | ||
self.backend.remove_file(self.key) | ||
|
||
def test_get_backend(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include docstrings on these tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by bb88ed1
84d18e9
to
3a9ec7e
Compare
Thanks for the pull request, @pomegranited! I've created OSPR-1808 to keep track of it in JIRA. JIRA is a place for product owners to prioritize feature reviews by the engineering development teams. Feel free to add as much of the following information to the ticket:
All technical communication about the code itself will still be done via the GitHub pull request interface. As a reminder, our process documentation is here. If you like, you can add yourself to the AUTHORS file for this repo, though that isn't required. Please see the CONTRIBUTING file for more information. |
Hi @nedbat ! We've asked for this and its related https://github.com/edx/edx-platform/pull/15446 to be considered for the Ginkgo release. Do you think that's feasible? Is there anything else we can do to make these PRs easier to verify and merge? CC @gsong |
We're trying to move this up the queue to get it in before the Ginkgo rc. |
Thank you, @nedbat ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me, I've confirmed it works on my local devstack and on your swift sandbox. Let's squash and get this merged.
Could you expand on this comment a bit? How exactly would submissions be lost? I'm understanding it as "there's no way to move from location A to location B", which seems reasonable. This isn't setting a default, so deployments that already use file upload will not be affected unless they opt-in, correct?
However, in practice, it was impossible to make the django backend preserve the same file destinations between all mechanisms, and so changing the backend on an existing deployment could result in lost submissions.
3a9ec7e
to
28ae4e4
Compare
Thank you @efischer19 ! I've squashed and rebased on the latest master, and will merge once tests pass. EDIT: Just saw your comment https://github.com/edx/edx-platform/pull/15446#discussion_r127292036 -- will leave the tagging to you.
Yes, that's correct. What I was trying to say was, if you change the ORA2 fileupload backend from e.g.
Correct. |
Adds a fileupload backend named "django", which uses the default django storage backend.
OpenCraft needs this change because the current
swift
backend doesn't work with OVH's SWIFT service. Theswift
backend relies on generating temporaryPOST/GET
URLs which are used to upload/download files, but OVH throws CORS-related errors when attempting to use these URLs in the browser.Instead of attempting to change the
swift
backend to work with OVH, we decided to add adjango
storage backend, which will work with the currently configured django storage settings on the platform. This fixes the issue for us with OVH, but also allows file uploads to work by default in the devstack.JIRA tickets: OSPR-1808
Sandbox URL:
Partner information: 3rd party-hosted open edX instance
Merge deadline: None
Testing instructions:
Devstacks use django FileSystemStorage by default, so they're a good place to test this change using
django.core.files.storage.FileSystemStorage
.open-craft:jill/ora2-django-storage
, the branch used in https://github.com/edx/edx-platform/pull/15446. This change:lms/urls.py
ORA2_FILEUPLOAD_BACKEND = "django"
inlms/envs/devstack.py
requirements/edx/base.txt
to install ORA2 from this branch.edxapp
user, runpaver run_all_servers
Edit
.Settings
, and scroll down to set:Upload Files
to save.The sandbox shown above uses SWIFT storage on OVH, and so it's a good place to test this change using
swift.storage.SwiftStorage
.Author notes and concerns:
This new
django
backend could in theory replace the existing backends, since most deployments are likely to use the same storage mechanism for ORA2 that they use on the platform.However, in practice, it was impossible to make the
django
backend preserve the same file destinations between all mechanisms, and so changing the backend on an existing deployment could result in lost submissions.Note: ORA2 appends the
[/{index}]
suffix for multiple file uploads, when{index} > 0
. When{index} == 0
, it is omitted.I.e.,
ORA2_FILEUPLOAD_BACKEND = 's3'
(default): stores to{bucket}/{prefix}/{key}[/{index}]
ORA2_FILEUPLOAD_BACKEND = 'swift'
: stores to{bucket}/{prefix}/{key}[/{index}]
ORA2_FILEUPLOAD_BACKEND = 'filesystem'
: stores two files,{media_root}/{bucket}/{prefix}/{key}[/{index}]/content
and{media_root}/{bucket}/{prefix}/{key}[/{index}]/metadata.json
, and creates any subdirectories required.ORA2_FILEUPLOAD_BACKEND = 'django'
: stores to{storage_root}/{prefix}/{key}[_{index}]
.The destination filename must be flattened from
{key}[/{index}]
to{key}[_{index}]
because it must be storage-agnostic, and so can't create subdirectories. Also, it must gracefully handle the cases where{index} == 0
and is therefore omitted from the key by ORA2, and where{index} > 0
, when it is included.Specifically, if we didn't replace the dir separator with an unerscore and the default django storage points to the local filesystem, then the first file would write to
{storage_root}/{prefix}/{key}
, and the next file would fail to write to{storage_root}/{prefix}/{key}/1
, because{storage_root}/{prefix}/{key}
already exists as a file, not a directory.Reviewers