Skip to content

Commit 5b331fe

Browse files
authored
set the storage backend properly to S3 if necessary for Django 5 (#3129)
1 parent a4f9fbd commit 5b331fe

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

main/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import cssutils
1414
import dj_database_url
1515
from celery.schedules import crontab
16+
from django.conf import global_settings
1617
from django.core.exceptions import ImproperlyConfigured
1718
from mitol.apigateway.settings import * # noqa: F403 # noqa: F403
1819
from mitol.common.envs import (
@@ -832,7 +833,9 @@
832833
if MITX_ONLINE_USE_S3:
833834
if CLOUDFRONT_DIST:
834835
AWS_S3_CUSTOM_DOMAIN = f"{CLOUDFRONT_DIST}.cloudfront.net"
835-
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
836+
# Override default storage backend to use S3 (Django 5.0+)
837+
STORAGES = global_settings.STORAGES.copy()
838+
STORAGES["default"]["BACKEND"] = "storages.backends.s3boto3.S3Boto3Storage"
836839

837840
FEATURES_DEFAULT = get_bool(
838841
name="FEATURES_DEFAULT",

main/settings_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_s3_settings(settings_sandbox):
5757
# Unset, we don't do S3
5858
settings_vars = settings_sandbox.patch({"MITX_ONLINE_USE_S3": "False"})
5959

60-
assert settings_vars.get("DEFAULT_FILE_STORAGE") is None
60+
assert settings_vars.get("STORAGES", {}).get("default", {}).get("BACKEND") is None
6161

6262
with pytest.raises(ImproperlyConfigured):
6363
settings_sandbox.patch({"MITX_ONLINE_USE_S3": "True"})
@@ -72,7 +72,7 @@ def test_s3_settings(settings_sandbox):
7272
}
7373
)
7474
assert (
75-
settings_vars.get("DEFAULT_FILE_STORAGE")
75+
settings_vars.get("STORAGES", {}).get("default", {}).get("BACKEND")
7676
== "storages.backends.s3boto3.S3Boto3Storage"
7777
)
7878

0 commit comments

Comments
 (0)