fix: Django52 use STORAGES instead of DEFAULT_FILE_STORAGE and STATICFILES_STORAGE#185
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR migrates Django configuration from deprecated DEFAULT_FILE_STORAGE and STATICFILES_STORAGE settings to the modern STORAGES dictionary pattern required for Django 5.2 compatibility.
- Replaced deprecated storage settings with the new
STORAGESconfiguration structure - Updated Python configuration files to conditionally set storage backends via
STORAGES - Updated YAML configuration files to define storage backends using the new format
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| py_configuration_files/credentials.py | Migrated from deprecated storage settings to conditional STORAGES configuration |
| configuration_files/lms.yml | Replaced deprecated DEFAULT_FILE_STORAGE with STORAGES dictionary definition |
| configuration_files/discovery.yml | Updated both DEFAULT_FILE_STORAGE and STATICFILES_STORAGE to use STORAGES format |
| configuration_files/cms.yml | Replaced deprecated DEFAULT_FILE_STORAGE with STORAGES dictionary definition |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if defaultfile_storage: | ||
| STORAGES["default"]["BACKEND"] = defaultfile_storage | ||
|
|
||
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | ||
|
|
||
| if staticfiles_storage: | ||
| STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage |
There was a problem hiding this comment.
The code attempts to access nested dictionary keys without ensuring the parent dictionaries exist. This will raise a KeyError if STORAGES is not already defined or if the 'default'/'staticfiles' keys don't exist. Consider using STORAGES.setdefault('default', {})['BACKEND'] = defaultfile_storage or ensure STORAGES is properly initialized first.
| if defaultfile_storage: | |
| STORAGES["default"]["BACKEND"] = defaultfile_storage | |
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | |
| if staticfiles_storage: | |
| STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage | |
| # Ensure STORAGES is defined | |
| if "STORAGES" not in globals(): | |
| STORAGES = {} | |
| if defaultfile_storage: | |
| STORAGES.setdefault("default", {})["BACKEND"] = defaultfile_storage | |
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | |
| if staticfiles_storage: | |
| STORAGES.setdefault("staticfiles", {})["BACKEND"] = staticfiles_storage |
| STORAGES["default"]["BACKEND"] = defaultfile_storage | ||
|
|
||
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | ||
|
|
||
| if staticfiles_storage: | ||
| STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage |
There was a problem hiding this comment.
The code attempts to access nested dictionary keys without ensuring the parent dictionaries exist. This will raise a KeyError if STORAGES is not already defined or if the 'default'/'staticfiles' keys don't exist. Consider using STORAGES.setdefault('default', {})['BACKEND'] = defaultfile_storage or ensure STORAGES is properly initialized first.
| STORAGES["default"]["BACKEND"] = defaultfile_storage | |
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | |
| if staticfiles_storage: | |
| STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage | |
| STORAGES.setdefault("default", {})["BACKEND"] = defaultfile_storage | |
| staticfiles_storage = os.environ.get("STATICFILES_STORAGE") | |
| if staticfiles_storage: | |
| STORAGES.setdefault("staticfiles", {})["BACKEND"] = staticfiles_storage |
deborahgu
left a comment
There was a problem hiding this comment.
the credentials side of this looks good to me. I put in a suggestion that I would like you to use (being consistent about the presence of underscores between environment variable name and corresponding variable name), but I'm not marking as request changes because it's a nitpick.
Description
This PR refactors the code to replace the deprecated
DEFAULT_FILE_STORAGEandSTATICFILES_STORAGEsettings with the more flexible and recommendedSTORAGES = {}pattern, a change that was recently done in various repos in community.For more details Refer to Jira links
2U Private Jira Link