Opened 17 months ago
Closed 16 months 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 , 17 months ago
Summary: | Improve misconfiguration of `STORAGES` setting → Prevent misconfiguration of `STORAGES` setting |
---|
comment:2 by , 17 months ago
Component: | Documentation → contrib.staticfiles |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 17 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 17 months ago
Has patch: | set |
---|
comment:5 by , 17 months ago
Patch needs improvement: | set |
---|
comment:9 by , 16 months ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Documentation improvements are welcome.
I agree that we could add a check for a
staticfiles
storage, e.g.staticfiles.E005
:You must define a 'staticfiles' storage in your :setting:
STORAGES
setting.
in thedjango.contrib.staticfiles.checks
.However, as far as I'm aware, you don't have to use the
default
storage so a new system check might be an issue for some projects.