Skip to content

Commit 085e01a

Browse files
committed
fix: update resolve_storage_backend function and fix tests
1 parent e8aeae7 commit 085e01a

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

common/djangoapps/util/storage.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""" Utility functions related to django storages """
22

3-
from typing import Optional
3+
from typing import Optional, List
44
from django.conf import settings
55
from django.core.files.storage import storages
66
from django.utils.module_loading import import_string
@@ -9,15 +9,16 @@
99
def resolve_storage_backend(
1010
storage_key: str,
1111
legacy_setting_key: str,
12-
legacy_sec_setting_key: str = None,
12+
legacy_sec_setting_keys: List[str] = None,
1313
options: Optional[dict] = None):
1414
"""
1515
Configures and returns a Django `Storage` instance, compatible with both Django 4 and Django 5.
1616
Params:
1717
storage_key = The key name saved in Django storages settings.
1818
legacy_setting_key = The key name saved in Django settings.
19-
legacy_sec_setting_key = For legacy dict settings like settings.BLOCK_STRUCTURES_SETTINGS.get('STORAGE_CLASS'),
20-
it is necessary to access a second-level key to retrieve the class path.
19+
legacy_sec_setting_keys = List of keys to get the storage class.
20+
For legacy dict settings like settings.BLOCK_STRUCTURES_SETTINGS.get('STORAGE_CLASS'),
21+
it is necessary to access a second-level key or above to retrieve the class path.
2122
legacy_options = Kwargs for the storage class.
2223
options = Kwargs for the storage class.
2324
Returns:
@@ -32,9 +33,10 @@ def resolve_storage_backend(
3233
"""
3334

3435
storage_path = getattr(settings, legacy_setting_key, None)
35-
if legacy_sec_setting_key and isinstance(storage_path, dict):
36-
# For legacy dict settings like CUSTOM_STORAGE = {"BACKEND": "cms.custom.."}
37-
storage_path = storage_path.get(legacy_sec_setting_key)
36+
if isinstance(storage_path, dict) and legacy_sec_setting_keys:
37+
for deep_setting_key in legacy_sec_setting_keys:
38+
# For legacy dict settings like settings.CUSTOM_STORAGE = {"BACKEND": "cms.custom.."}
39+
storage_path = storage_path.get(deep_setting_key)
3840
storages_config = getattr(settings, 'STORAGES', {})
3941

4042
if options is None:

lms/djangoapps/verify_student/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ def _storage(self):
914914
config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]
915915

916916
# Default to the S3 backend for backward compatibility
917-
storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto3.S3Boto3Storage")
918917
storage_kwargs = config.get("STORAGE_KWARGS", {})
919918

920919
# Map old settings to the parameters expected by the storage backend
@@ -927,9 +926,9 @@ def _storage(self):
927926
storage_kwargs["querystring_expire"] = self.IMAGE_LINK_DURATION
928927

929928
return resolve_storage_backend(
930-
storage_key="software_secure",
931-
legacy_setting_key="SOFTWARE_SECURE",
932-
legacy_sec_setting_key="STORAGE_CLASS",
929+
storage_key="verify_student",
930+
legacy_setting_key="VERIFY_STUDENT",
931+
legacy_sec_setting_keys=["STORAGE_CLASS"],
933932
options=storage_kwargs
934933
)
935934

lms/djangoapps/verify_student/tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"CERT_VERIFICATION_PATH": False,
4848
},
4949
"DAYS_GOOD_FOR": 10,
50+
"STORAGE_CLASS": "storages.backends.s3boto3.S3Boto3Storage"
5051
}
5152

5253

lms/djangoapps/verify_student/tests/test_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ def test_submit_photos_error_does_not_send_email(self):
13011301
"CERT_VERIFICATION_PATH": False,
13021302
},
13031303
"DAYS_GOOD_FOR": 10,
1304+
"STORAGE_CLASS": "storages.backends.s3boto3.S3Boto3Storage"
13041305
})
13051306
@httpretty.activate
13061307
def test_submit_photos_for_reverification(self):

openedx/core/djangoapps/content/block_structure/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _bs_model_storage():
8686
return resolve_storage_backend(
8787
storage_key="block_structures_settings",
8888
legacy_setting_key="BLOCK_STRUCTURES_SETTINGS",
89-
legacy_sec_setting_key="STORAGE_CLASS",
89+
legacy_sec_setting_keys=["STORAGE_CLASS"],
9090
options=storage_kwargs
9191
)
9292

0 commit comments

Comments
 (0)