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

feat: add support for picking storage config from settings #344

Merged
merged 2 commits into from Sep 15, 2023

Conversation

iamsobanjaved
Copy link

Adding support for picking storage class from the settings. If not defined, go with the system's default storage.

Copy link

@connorhaugh connorhaugh left a 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.

Copy link
Member

@pdpinch pdpinch left a 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.

@@ -2,4 +2,4 @@
Module for StaffGradedAssignmentXBlock.
"""

__version__ = "0.22.0"
__version__ = "0.23.0"
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

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

@iamsobanjaved
Copy link
Author

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?

Yes making the storage configurable for edX.

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.

Yes, if this setting isn't defined, it will use default_storage from django.core.storage.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Merging #344 (ce26862) into master (907d670) will increase coverage by 0.47%.
The diff coverage is 100.00%.

@@            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              
Files Changed Coverage Δ
edx_sga/sga.py 64.62% <100.00%> (ø)
edx_sga/tasks.py 47.05% <100.00%> (ø)
edx_sga/tests/test_utils.py 100.00% <100.00%> (ø)
edx_sga/utils.py 94.73% <100.00%> (+0.98%) ⬆️

Copy link

@arslanashraf7 arslanashraf7 left a 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(

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:

  1. nit: get_storage_class in Django automatically fallbacks to and returns default storage, e.g. FileStorage if the provided args are None 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.

  2. nit: This can throw ImportError if the provided settings/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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, but we still have to call the constructor with the keyword arguments too. It would still require the conditional statement.

  2. 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():

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.

Copy link
Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Author

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

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.

Suggested change
# .. 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@iamsobanjaved
Copy link
Author

@arslanashraf7 Kindly review this now

Copy link

@arslanashraf7 arslanashraf7 left a 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.

@arslanashraf7 arslanashraf7 merged commit 65d039f into mitodl:master Sep 15, 2023
3 checks passed
@odlbot odlbot mentioned this pull request Sep 15, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants