Skip to content

feat: deprecate get_storage_class in core/storage.py - #36910

Merged
feanil merged 5 commits into
openedx:masterfrom
dwong2708:django5-storage-36739
Aug 7, 2025
Merged

feanil merged 5 commits into
openedx:masterfrom
dwong2708:django5-storage-36739

Conversation

@dwong2708

@dwong2708 dwong2708 commented Jun 13, 2025 •

Copy link
Copy Markdown
Contributor

Description

Fixes: #36739

The main goal is to modify the get_storage_class function referenced here in order to deprecate it.
However, a few special changes have been made, as described below:

  • In this file, get_storage_class was replaced by the generic resolve_storage function.
  • A similar update was made here.

Why does the get_storage_class function still exist with a new implementation that uses import_string?
This change is related to the DjangoStorageReportStore class and its parent implementation. Specifically, here, a dynamic logic is used to define the storage backend.

Given the complexity of that logic, I recommend creating a separate ticket to refactor this part of the code.

Lastly, the resolve_storage_backend function was updated to support a legacy_sec_setting_keys parameter. This allows it to handle storage settings defined as nested dictionaries. For example:

settings.VERIFY_STUDENT = {
    "STORAGE_CLASS": "storage.path.class"
}

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 13, 2025
@openedx-webhooks

openedx-webhooks commented Jun 13, 2025 •

Copy link
Copy Markdown

Thanks for the pull request, @dwong2708!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Jun 13, 2025
@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 2 times, most recently from 52e93e7 to bed450a Compare June 13, 2025 22:21
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Jun 16, 2025
@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 6 times, most recently from 3033d45 to 085e01a Compare June 18, 2025 15:30
@dwong2708
dwong2708 marked this pull request as ready for review June 18, 2025 15:31
@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 2 times, most recently from 2607ef4 to 6197b2d Compare June 20, 2025 15:40
@dwong2708
dwong2708 requested review from awais786 and feanil June 20, 2025 16:37
@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 2 times, most recently from f6a4a32 to d0a3e95 Compare June 20, 2025 19:37
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jun 20, 2025

@feanil feanil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comments but generally I think the approach is good, it will be nice to clean it all up in a future release but I think this is good for transitioning.

Comment thread common/djangoapps/util/storage.py Resolved
Comment thread common/djangoapps/util/storage.py Outdated
if isinstance(storage_path, dict) and legacy_sec_setting_keys:
for deep_setting_key in legacy_sec_setting_keys:
# For legacy dict settings like settings.CUSTOM_STORAGE = {"BACKEND": "cms.custom.."}
storage_path = storage_path.get(deep_setting_key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the legacy_sec_setting_keys has 2 items in the list, and the first one returns None I think this will throw an exception when you try None.get...

We should add a test case for that and I think it's fine to raise the exception but maybe catch and re-raise it with extra context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to add an exception as suggested, but I noticed that when running pytest, the exception is raised immediately. This happens because calls like this one to a CustomizableFileField are executed eagerly during model field initialization.

Because of that, I decided to keep the code as a simple validation that falls back to the default storage when needed. What do you think about this approach?

config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]

# Default to the S3 backend for backward compatibility
storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto3.S3Boto3Storage")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're changing behavior here a bit, previously if no storage class was provided it would fallback to S3 specifically. Now it will fallback to the default storage class. I think this is an improvement but because it's also a change in behavior, we should communicate it and make sure it's in the operator/dev notes for Ulmo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of adding an extra parameter to resolve_storage_backend to allow passing in a fallback_storage_class, and use that as the default instead of FileSystemStorage. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that's necessary, I think we can just make a note about this. Previously this would fail if you didn't explicitly configure it, now it will fallback to your default storage class which I think is an improvement, we just need to document it in the Ulmo notes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I just updated the dev notes for Ulmo. Thanks Feanil.

@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 2 times, most recently from eefaf84 to fe002c0 Compare July 17, 2025 21:28
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Blocked in Contributions Jul 30, 2025
@mphilbrick211 mphilbrick211 moved this from Blocked to Ready for Review in Contributions Jul 30, 2025
@feanil feanil self-assigned this Aug 1, 2025

@feanil feanil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dwong2708 just a couple of questions but I'm hoping we can land this soon.

config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]

# Default to the S3 backend for backward compatibility
storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto3.S3Boto3Storage")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that's necessary, I think we can just make a note about this. Previously this would fail if you didn't explicitly configure it, now it will fallback to your default storage class which I think is an improvement, we just need to document it in the Ulmo notes.

"CERT_VERIFICATION_PATH": False,
},
"DAYS_GOOD_FOR": 10,
"STORAGE_CLASS": "storages.backends.s3boto3.S3Boto3Storage"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you add this setting to the test? Is this required now or was this just to improve test coverage? If it's required, do we need to document that somewhere so that operators know to change their settings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is now a requirement. Where is the appropriate place to document it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also add this to the Ulmo page but we'll want to communicate it to people who are close following master so probably also worth posting it to the discussion forums. There is an @early-deployers group you can tag on a post, just post it as a maintainers announcement.

FYI @jristau1984 @timmc-edx as this will be something 2U will need to add to their settings before we merge this change to master as a part of the Django 5.2 upgrade.

Correct me if I'm wrong @dwong2708 but I think before the storage class was defaulting to S3 rather than whatever the default storage class was set to. So now if you want to explicitly use s3 storage for this, you have to set it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the top-level STORAGE_CLASS setting, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should also add this to the Ulmo page but we'll want to communicate it to people who are close following master so probably also worth posting it to the discussion forums. There is an @early-deployers group you can tag on a post, just post it as a maintainers announcement.

FYI @jristau1984 @timmc-edx as this will be something 2U will need to add to their settings before we merge this change to master as a part of the Django 5.2 upgrade.

Correct me if I'm wrong @dwong2708 but I think before the storage class was defaulting to S3 rather than whatever the default storage class was set to. So now if you want to explicitly use s3 storage for this, you have to set it.

That's correct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the top-level STORAGE_CLASS setting, right?

In Django settings, the storage class for VERIFY_STUDENT is defined like this:

VERIFY_STUDENT = {
    "SOFTWARE_SECURE": {},
    "DAYS_GOOD_FOR": 10,
    "STORAGE_CLASS": "storages.backends.s3boto3.S3Boto3Storage"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should also add this to the Ulmo page but we'll want to communicate it to people who are close following master so probably also worth posting it to the discussion forums. There is an @early-deployers group you can tag on a post, just post it as a maintainers announcement.

FYI @jristau1984 @timmc-edx as this will be something 2U will need to add to their settings before we merge this change to master as a part of the Django 5.2 upgrade.

Correct me if I'm wrong @dwong2708 but I think before the storage class was defaulting to S3 rather than whatever the default storage class was set to. So now if you want to explicitly use s3 storage for this, you have to set it.

Done. Here the announcement https://discuss.openedx.org/t/deprecation-notice-verify-student-storage-class-in-favor-of-django-s-storages/16707

@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch 3 times, most recently from 1184c17 to 5f40fe6 Compare August 5, 2025 18:59
@dwong2708
dwong2708 requested a review from feanil August 5, 2025 19:01

@feanil feanil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good, I'm planning on Merging it Thursday so that early deployers have enough time to react if they need to to the one breaking change.

@awais786 awais786 added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Aug 6, 2025
@open-craft-grove

Copy link
Copy Markdown

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dwong2708
dwong2708 force-pushed the django5-storage-36739 branch from 5f40fe6 to 7479beb Compare August 6, 2025 19:25
@open-craft-grove

Copy link
Copy Markdown

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@feanil
feanil merged commit 7a1788b into openedx:master Aug 7, 2025
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Aug 7, 2025
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-sandbox open-craft-grove should create a sandbox environment from this PR mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

RemovedInDjango51Warning for get_storage_class in openedx/core/storage.py

8 participants