Opened 2 years ago
Closed 2 years ago
#34712 closed Cleanup/optimization (fixed)
Prevent misconfiguration of `STORAGES` setting
| Reported by: | Bruno Alla | Owned by: | Bruno Alla |
|---|---|---|---|
| Component: | contrib.staticfiles | Version: | 4.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
The new STORAGES setting added in #26029 is great and super flexible. While trying to migrate Cookiecutter Django to use it [1], I noticed that it's quite easy to break the configuration of one of the storages: if I want to override only one of the 2 default storages (e.g. staticfiles), then I might be tempted to set:
STORAGES = {
"staticfiles": {"BACKEND": "MyCustomStorage"},
}
Which would raise a InvalidStorageError when trying to upload a FileField somewhere. AFAIK, nothing warns the user of this misconfiguration until this point.
I think that one might assume that the dictionary defined by the user would be "merged" with the default value. I'm assuming that implementing behaviour could be considered too much of breaking change to the behaviour etablished in 4.2, but I think the documentation could outline better the existing behaviour when only one storage is defined by the user.
Another thing that could be maybe be added is a deployment check, to make sure that both default and staticfiles storages are present in the setting.
[1] https://github.com/cookiecutter/cookiecutter-django/pull/4457
Change History (9)
comment:1 by , 2 years ago
| Summary: | Improve misconfiguration of `STORAGES` setting → Prevent misconfiguration of `STORAGES` setting |
|---|
comment:2 by , 2 years ago
| Component: | Documentation → contrib.staticfiles |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 2 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 2 years ago
| Has patch: | set |
|---|
comment:5 by , 2 years ago
| Patch needs improvement: | set |
|---|
comment:9 by , 2 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Documentation improvements are welcome.
I agree that we could add a check for a
staticfilesstorage, e.g.staticfiles.E005:You must define a 'staticfiles' storage in your :setting:STORAGESsetting.in thedjango.contrib.staticfiles.checks.However, as far as I'm aware, you don't have to use the
defaultstorage so a new system check might be an issue for some projects.