Skip to content

Commit 8a58800

Browse files
committed
fix: storage compatibility issue for django42
1 parent 2ab3cf0 commit 8a58800

File tree

5 files changed

+19
-81
lines changed

5 files changed

+19
-81
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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,14 @@
462462
EXTRA_APPS = []
463463
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
464464

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
465+
STORAGES = {
466+
"default": {
467+
"BACKEND": "django.core.files.storage.FileSystemStorage",
468+
},
469+
"staticfiles": {
470+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
471+
},
472+
}
482473

483474
CACHES = {
484475
"default": {

credentials/settings/devstack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
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(STORAGES["staticfiles"]["BACKEND"], "django.contrib.staticfiles.storage.StaticFilesStorage")
5050
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5151

5252
# 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)