Skip to content

Commit 66ca851

Browse files
committed
fix: storage compatibility issue for django42
1 parent 2ab3cf0 commit 66ca851

File tree

5 files changed

+21
-82
lines changed

5 files changed

+21
-82
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
make static
6464
make tests
6565
- name: Run code coverage
66-
if: matrix.python-version == '3.12' && matrix.django-version == 'django52'
66+
if: matrix.python-version == '3.12' && matrix.django-version == 'django42'
6767
uses: codecov/codecov-action@v5
6868
with:
6969
flags: unittests

credentials/apps/core/tests/test_storage_settings.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

credentials/settings/base.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from os.path import abspath, dirname, join
44

55
from corsheaders.defaults import default_headers as corsheaders_default_headers
6-
import django
76
from django.conf.global_settings import LANGUAGES_BIDI
87
from edx_toggles.toggles import WaffleSwitch
98
from edx_django_utils.plugins import get_plugin_apps, add_plugins
@@ -462,23 +461,14 @@
462461
EXTRA_APPS = []
463462
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
464463

465-
DEFAULT_FILE_STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"
466-
STATICFILES_STORAGE_BACKEND = "django.contrib.staticfiles.storage.StaticFilesStorage"
467-
468-
if django.VERSION >= (4, 2):
469-
# Use new STORAGES setting (available from Django 4.2)
470-
STORAGES = {
471-
"default": {
472-
"BACKEND": DEFAULT_FILE_STORAGE_BACKEND,
473-
},
474-
"staticfiles": {
475-
"BACKEND": STATICFILES_STORAGE_BACKEND,
476-
},
477-
}
478-
else:
479-
# For Django < 4.2 or packages still using legacy settings
480-
DEFAULT_FILE_STORAGE = DEFAULT_FILE_STORAGE_BACKEND
481-
STATICFILES_STORAGE = STATICFILES_STORAGE_BACKEND
464+
STORAGES = {
465+
"default": {
466+
"BACKEND": "django.core.files.storage.FileSystemStorage",
467+
},
468+
"staticfiles": {
469+
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
470+
},
471+
}
482472

483473
CACHES = {
484474
"default": {

credentials/settings/devstack.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
4444
EMAIL_FILE_PATH = "/tmp/credentials-emails"
4545

46-
DEFAULT_FILE_STORAGE = os.environ.get("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage")
46+
DEFAULT_FILE_STORAGE = os.environ.get(STORAGES["default"]["BACKEND"], "django.core.files.storage.FileSystemStorage")
4747
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
4848

49-
STATICFILES_STORAGE = os.environ.get("STATICFILES_STORAGE", "django.contrib.staticfiles.storage.StaticFilesStorage")
49+
STATICFILES_STORAGE = os.environ.get(
50+
STORAGES["staticfiles"]["BACKEND"], "django.contrib.staticfiles.storage.StaticFilesStorage"
51+
)
5052
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5153

5254
# OAuth2 variables specific to social-auth/SSO login use case.

credentials/settings/test.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,14 @@
3636
# Local Directories
3737
TEST_ROOT = path("test_root")
3838

39-
DEFAULT_FILE_STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"
40-
STATICFILES_STORAGE_BACKEND = "django.contrib.staticfiles.storage.StaticFilesStorage"
41-
42-
if django.VERSION >= (4, 2):
43-
# Use new STORAGES setting (available from Django 4.2)
44-
STORAGES = {
45-
"default": {
46-
"BACKEND": DEFAULT_FILE_STORAGE_BACKEND,
47-
},
48-
"staticfiles": {
49-
"BACKEND": STATICFILES_STORAGE_BACKEND,
50-
},
51-
}
52-
else:
53-
# For Django < 4.2 or packages still using legacy settings
54-
DEFAULT_FILE_STORAGE = DEFAULT_FILE_STORAGE_BACKEND
55-
STATICFILES_STORAGE = STATICFILES_STORAGE_BACKEND
56-
39+
STORAGES = {
40+
"default": {
41+
"BACKEND": "django.core.files.storage.FileSystemStorage",
42+
},
43+
"staticfiles": {
44+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
45+
},
46+
}
5747
MEDIA_ROOT = str(TEST_ROOT / "uploads")
5848
MEDIA_URL = "/static/uploads/"
5949

0 commit comments

Comments
 (0)