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
feat: add support for picking storage config from settings #344
Conversation
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.
Not a maintainer, but lgtm.
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.
Can you explain a bit more about what this change does? I think you want to be able to configure a separate storage location for SGA submissions from other user submissions. Is that correct?
I also want to confirm that this new setting won't be required, and existing installations with no value for SGA_STORAGE_SETTINGS
will continue to function.
I left a couple of comments about documentation, but I'll ask someone else from our team to review the code.
edx_sga/__init__.py
Outdated
@@ -2,4 +2,4 @@ | |||
Module for StaffGradedAssignmentXBlock. | |||
""" | |||
|
|||
__version__ = "0.22.0" | |||
__version__ = "0.23.0" |
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 remove the version change. Our release bot will take care of this.
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.
Removed
from edx_sga.constants import BLOCK_SIZE | ||
|
||
|
||
def get_default_storage(): | ||
sga_storage_settings = getattr(settings, "SGA_STORAGE_SETTINGS", None) |
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.
Is this introducing a new configuration setting to edx-platform for this xBlock?
Please follow the guidelines in OEP-17 for adding annotations for settings and flags.
In the annotation, please include an example of the data structure for SGA_STORAGE_SETTINGS
.
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.
Yes introducing new configuration, added the annotations
3604872
to
e607305
Compare
Yes making the storage configurable for edX.
Yes, if this setting isn't defined, it will use |
Codecov Report
@@ Coverage Diff @@
## master #344 +/- ##
==========================================
+ Coverage 53.27% 53.75% +0.47%
==========================================
Files 16 16
Lines 1663 1680 +17
Branches 114 115 +1
==========================================
+ Hits 886 903 +17
Misses 764 764
Partials 13 13
|
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.
Thanks for creating this PR @iamsobanjaved.
I just did the code review for now and suggested a couple of changes, Let me know what you think about them.
I'll test the PR in re-review.
sga_storage_settings = getattr(settings, "SGA_STORAGE_SETTINGS", None) | ||
|
||
if sga_storage_settings: | ||
return get_storage_class( |
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 have two things in mind regarding this:
-
nit: get_storage_class in Django automatically fallbacks to and returns default storage, e.g.
FileStorage
if the provided args areNone or empty
. We can use this and easily remove some condition statements and code lines.Let me know, If you think that would be less readable.
-
nit: This can throw
ImportError
if the providedsettings/class name
isn't correct.- Now we can either 1) let the error bubble up in the logs or 2) Catch it and raise a properly formatted named exception such as
ImproperlyConfigured from django.core.exceptions
. I'm fine either way so this change is kind of optional, I just wanted to mention it anyway.
- Now we can either 1) let the error bubble up in the logs or 2) Catch it and raise a properly formatted named exception such as
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.
-
Yes, but we still have to call the constructor with the keyword arguments too. It would still require the conditional statement.
-
Yes it can throw an error, but there is a single source from which this value will come, that's why skipped throw catch in first place.
from edx_sga.constants import BLOCK_SIZE | ||
|
||
|
||
def get_default_storage(): |
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.
Can you write a simple test for this? That would go in test_utils.py.
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.
Added
edx_sga/utils.py
Outdated
from edx_sga.constants import BLOCK_SIZE | ||
|
||
|
||
def get_default_storage(): | ||
""" | ||
Get config for storage from settings, use DJango's default_storage if no such settings defined |
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.
Get config for storage from settings, use DJango's default_storage if no such settings defined | |
Get config for storage from settings, use Django's default_storage if no such settings are defined |
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.
Done
""" | ||
# .. setting_name: SGA_STORAGE_SETTINGS | ||
# .. setting_default: {} | ||
# .. setting_description: Specifies the storage class and keyword arguments to use in the constructor |
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 think this might be a better description.
# .. setting_description: Specifies the storage class and keyword arguments to use in the constructor | |
# .. setting_description: Specifies the storage class and keyword arguments to use in the constructor. | |
# .. Default Storage would be used if this setting is not specified. |
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.
Done
e607305
to
ce26862
Compare
@arslanashraf7 Kindly review this now |
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.
Thanks for making all the changes. Looks great 👍 . Things worked while testing.
Adding support for picking storage class from the settings. If not defined, go with the system's default storage.