Refs #748 - Serialize storage alias whenever possible #788
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #748 where users experience storage errors with Django 4.2+ when using cloud storage backends (S3, Google Cloud Storage, etc.).
The Problem
Users reported errors like:
When using Django's
STORAGESconfiguration with OPTIONS (bucket names, credentials, etc.), sorl-thumbnail would fail because storage instances were created without these required OPTIONS.Real-world impact: Projects like NetBox are blocked by this issue (netbox-community/netbox#20212), unable to use S3 storage with sorl-thumbnail until this fix is released.
Root Cause
While commit b348c63 added support for Django storage aliases in
get_or_create_storage(), the serialization still used the backend class path instead of the alias. This meant:storages["default"]with OPTIONS"storages.backends.s3.S3Storage"(class path)get_module_class()()without OPTIONS → FAILSAs @panizza noted in issue #748:
The Solution
This PR completes the fix by ensuring storage aliases are serialized whenever possible:
storages["default"]with OPTIONS"default"(alias)storages["default"]with OPTIONS → SUCCESSChanges
serialize_storage()to return the storage alias (e.g., "default") instead of the backend class path when the alias exists in Django'sSTORAGESconfigurationRelated Issues
Test Plan
test_storage_serializepasses - directly validates storage alias serializationTesting with Real S3 Configuration
This fix allows users to configure S3 storage like:
And thumbnails will now correctly serialize/deserialize using the "default" alias, preserving all OPTIONS through the entire lifecycle.