summaryrefslogtreecommitdiff
path: root/django/conf/__init__.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-18 18:11:24 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-18 18:12:30 +0200
commitd34db6602e89387ae9ddc9ae94defe5c838acb88 (patch)
treeb6415fa1fec5fe3fd8aef6987c845bf7f86dbe57 /django/conf/__init__.py
parenta22aeef55551dc6827b11afcc994a342fca93453 (diff)
[4.2.x] Fixed #34773 -- Fixed syncing DEFAULT_FILE_STORAGE/STATICFILES_STORAGE settings with STORAGES.
Thanks Petr DlouhĂ˝ for the report. Bug in 32940d390a00a30a6409282d314d617667892841. Backport of 6b965c600054f970bdf94017ecf2e0e6e0a4326b from main
Diffstat (limited to 'django/conf/__init__.py')
-rw-r--r--django/conf/__init__.py48
1 files changed, 40 insertions, 8 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 7849abbdbb..f63df722c2 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -271,6 +271,9 @@ class Settings:
raise ImproperlyConfigured(
"DEFAULT_FILE_STORAGE/STORAGES are mutually exclusive."
)
+ self.STORAGES[DEFAULT_STORAGE_ALIAS] = {
+ "BACKEND": self.DEFAULT_FILE_STORAGE
+ }
warnings.warn(DEFAULT_FILE_STORAGE_DEPRECATED_MSG, RemovedInDjango51Warning)
if self.is_overridden("STATICFILES_STORAGE"):
@@ -278,7 +281,22 @@ class Settings:
raise ImproperlyConfigured(
"STATICFILES_STORAGE/STORAGES are mutually exclusive."
)
+ self.STORAGES[STATICFILES_STORAGE_ALIAS] = {
+ "BACKEND": self.STATICFILES_STORAGE
+ }
warnings.warn(STATICFILES_STORAGE_DEPRECATED_MSG, RemovedInDjango51Warning)
+ # RemovedInDjango51Warning.
+ if self.is_overridden("STORAGES"):
+ setattr(
+ self,
+ "DEFAULT_FILE_STORAGE",
+ self.STORAGES.get(DEFAULT_STORAGE_ALIAS, {}).get("BACKEND"),
+ )
+ setattr(
+ self,
+ "STATICFILES_STORAGE",
+ self.STORAGES.get(STATICFILES_STORAGE_ALIAS, {}).get("BACKEND"),
+ )
def is_overridden(self, setting):
return setting in self._explicit_settings
@@ -331,14 +349,28 @@ class UserSettingsHolder:
warnings.warn(USE_DEPRECATED_PYTZ_DEPRECATED_MSG, RemovedInDjango50Warning)
# RemovedInDjango51Warning.
if name == "STORAGES":
- self.STORAGES.setdefault(
- DEFAULT_STORAGE_ALIAS,
- {"BACKEND": "django.core.files.storage.FileSystemStorage"},
- )
- self.STORAGES.setdefault(
- STATICFILES_STORAGE_ALIAS,
- {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
- )
+ if default_file_storage := self.STORAGES.get(DEFAULT_STORAGE_ALIAS):
+ super().__setattr__(
+ "DEFAULT_FILE_STORAGE", default_file_storage.get("BACKEND")
+ )
+ else:
+ self.STORAGES.setdefault(
+ DEFAULT_STORAGE_ALIAS,
+ {"BACKEND": "django.core.files.storage.FileSystemStorage"},
+ )
+ if staticfiles_storage := self.STORAGES.get(STATICFILES_STORAGE_ALIAS):
+ super().__setattr__(
+ "STATICFILES_STORAGE", staticfiles_storage.get("BACKEND")
+ )
+ else:
+ self.STORAGES.setdefault(
+ STATICFILES_STORAGE_ALIAS,
+ {
+ "BACKEND": (
+ "django.contrib.staticfiles.storage.StaticFilesStorage"
+ ),
+ },
+ )
def __delattr__(self, name):
self._deleted.add(name)