jazzband / sorl-thumbnail

Thumbnails for Django
https://sorl-thumbnail.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.74k stars 495 forks source link

django 4.2 - storage options (problem with s3 and template tag) #748

Open pziewiec opened 11 months ago

pziewiec commented 11 months ago
@lru_cache
def get_or_create_storage(storage):
    return get_module_class(storage)()

sorl/thumbnail/images.py:23 - storage options parameter is missing

check this way: https://github.com/django/django/blob/b0ec87b8578147be4357c90eabcd2b916c780810/django/core/files/storage/handler.py#L38C38-L38C38

emdede commented 3 weeks ago

For anyone that finds themselves here looking for a solution. This is what I did as a workaround in my project:

# my_app/utils.py
def alias_default_storage(*args):
    from django.core.files.storage import storages

    return storages["default"] # or another key

# settings.py
THUMBNAIL_STORAGE = "my_app.utils.alias_default_storage"

from sorl.thumbnail import images

from my_app.utils import alias_default_storage

images.get_or_create_storage = alias_default_storage

There is also an additional problem when sorl-thumbnail is used in conjunction with filer because filer at the moment has a similar problem. To fix this particular issue there is at least no need to manually patch code but you do have to explicitly set the FILER_STORAGES engine options:

# settings.py

FILER_STORAGES = {
    "public": {
        "main": {
            "ENGINE": "storages.backends.s3.S3Storage",
            # Mirror the OPTIONS kwargs provided to your django storage
            "OPTIONS": {
                "bucket_name": media_bucket_name,
                "querystring_auth": False,
            },
        },
    }
}