Skip to content

Commit a7c73b9

Browse files
authored
Fixed #34821 -- Prevented DEFAULT_FILE_STORAGE/STATICFILES_STORAGE settings from mutating the main STORAGES.
Regression in 6b965c6.
1 parent 9381700 commit a7c73b9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

django/conf/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ def __init__(self, settings_module):
222222
raise ImproperlyConfigured(
223223
"DEFAULT_FILE_STORAGE/STORAGES are mutually exclusive."
224224
)
225-
self.STORAGES[DEFAULT_STORAGE_ALIAS] = {
226-
"BACKEND": self.DEFAULT_FILE_STORAGE
225+
self.STORAGES = {
226+
**self.STORAGES,
227+
DEFAULT_STORAGE_ALIAS: {"BACKEND": self.DEFAULT_FILE_STORAGE},
227228
}
228229
warnings.warn(DEFAULT_FILE_STORAGE_DEPRECATED_MSG, RemovedInDjango51Warning)
229230

@@ -232,8 +233,9 @@ def __init__(self, settings_module):
232233
raise ImproperlyConfigured(
233234
"STATICFILES_STORAGE/STORAGES are mutually exclusive."
234235
)
235-
self.STORAGES[STATICFILES_STORAGE_ALIAS] = {
236-
"BACKEND": self.STATICFILES_STORAGE
236+
self.STORAGES = {
237+
**self.STORAGES,
238+
STATICFILES_STORAGE_ALIAS: {"BACKEND": self.STATICFILES_STORAGE},
237239
}
238240
warnings.warn(STATICFILES_STORAGE_DEPRECATED_MSG, RemovedInDjango51Warning)
239241
# RemovedInDjango51Warning.

docs/releases/4.2.6.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ Django 4.2.6 fixes several bugs in 4.2.5.
99
Bugfixes
1010
========
1111

12-
* ...
12+
* Fixed a regression in Django 4.2.5 where overriding the deprecated
13+
``DEFAULT_FILE_STORAGE`` and ``STATICFILES_STORAGE`` settings in tests caused
14+
the main ``STORAGES`` to mutate (:ticket:`34821`).

tests/deprecation/test_storages.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_override_settings_warning(self):
3232
pass
3333

3434
def test_settings_init(self):
35+
old_staticfiles_storage = settings.STORAGES.get(STATICFILES_STORAGE_ALIAS)
3536
settings_module = ModuleType("fake_settings_module")
3637
settings_module.USE_TZ = True
3738
settings_module.STATICFILES_STORAGE = (
@@ -49,6 +50,11 @@ def test_settings_init(self):
4950
),
5051
},
5152
)
53+
# settings.STORAGES is not mutated.
54+
self.assertEqual(
55+
settings.STORAGES.get(STATICFILES_STORAGE_ALIAS),
56+
old_staticfiles_storage,
57+
)
5258
finally:
5359
del sys.modules["fake_settings_module"]
5460

@@ -161,6 +167,7 @@ def test_override_settings_warning(self):
161167
pass
162168

163169
def test_settings_init(self):
170+
old_default_storage = settings.STORAGES.get(DEFAULT_STORAGE_ALIAS)
164171
settings_module = ModuleType("fake_settings_module")
165172
settings_module.USE_TZ = True
166173
settings_module.DEFAULT_FILE_STORAGE = "django.core.files.storage.Storage"
@@ -172,6 +179,11 @@ def test_settings_init(self):
172179
fake_settings.STORAGES[DEFAULT_STORAGE_ALIAS],
173180
{"BACKEND": "django.core.files.storage.Storage"},
174181
)
182+
# settings.STORAGES is not mutated.
183+
self.assertEqual(
184+
settings.STORAGES.get(DEFAULT_STORAGE_ALIAS),
185+
old_default_storage,
186+
)
175187
finally:
176188
del sys.modules["fake_settings_module"]
177189

0 commit comments

Comments
 (0)