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
committerGitHub <noreply@github.com>2023-08-18 18:11:24 +0200
commit6b965c600054f970bdf94017ecf2e0e6e0a4326b (patch)
treec936a01a0dee84314d7fe6b71b687dea25f6b51e /django/conf/__init__.py
parentd25f3892114466d689fd6936f79f3bd9a9acc30e (diff)
Fixed #34773 -- Fixed syncing DEFAULT_FILE_STORAGE/STATICFILES_STORAGE settings with STORAGES.
Thanks Petr DlouhĂ˝ for the report. Bug in 32940d390a00a30a6409282d314d617667892841.
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 da461ecc02..e03369d321 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -222,6 +222,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"):
@@ -229,7 +232,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
@@ -276,14 +294,28 @@ class UserSettingsHolder:
super().__setattr__(name, value)
# 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)