easy-thumbnails icon indicating copy to clipboard operation
easy-thumbnails copied to clipboard

Breaks with Django 5.1 | ImportError: 'get_storage_class' from 'django.core.files.storage'

Open blu3f1r3 opened this issue 1 year ago • 4 comments

With the new Django 5.1 version the latest version breaks:

app-1  |   File "/app/apps/core/fields.py", line 20, in <module>
app-1  |     from easy_thumbnails.files import get_thumbnailer
app-1  |   File "/usr/local/lib/python3.11/site-packages/easy_thumbnails/files.py", line 13, in <module>
app-1  |     from easy_thumbnails import engine, exceptions, models, utils, signals, storage
app-1  |   File "/usr/local/lib/python3.11/site-packages/easy_thumbnails/storage.py", line 43, in <module>
app-1  |     thumbnail_default_storage = get_storage()
app-1  |                                 ^^^^^^^^^^^^^
app-1  |   File "/usr/local/lib/python3.11/site-packages/easy_thumbnails/storage.py", line 18, in get_storage
app-1  |     from django.core.files.storage import get_storage_class
app-1  | ImportError: cannot import name 'get_storage_class' from 'django.core.files.storage' (/usr/local/lib/python3.11/site-packages/django/core/files/storage/__init__.py)

blu3f1r3 avatar Aug 15 '24 08:08 blu3f1r3

To prevent this you can set THUMBNAIL_DEFAULT_STORAGE_ALIAS in settings (THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'default' for example) as workaround

Miketsukami avatar Aug 15 '24 11:08 Miketsukami

Workaround doesn't work for me. Still hitting a

    thumbnail_default_storage = get_storage()
  File "....../venv/lib/python3.10/site-packages/easy_thumbnails/storage.py", line 24, in get_storage
    from django.core.files.storage import get_storage_class
ImportError: cannot import name 'get_storage_class' from 'django.core.files.storage' (......../venv/lib/python3.10/site-packages/django/core/files/storage/__init__.py)

I checked storage.py, and I seem to be hitting the InvalidStorageError in get_storage(). The storages from from django.core.files.storage import storages prints as a django.core.files.storage.handler.StorageHandler object. storages._storages is an empty dict. I wasn't able to investigate handler.py, which contains StorageHandler, because any print statements and other edits anywhere in the code seem to not update. I do know that I hit the Could not find config for '{alias}' in settings.STORAGES InvalidStorage Error. Don't care to investigate further, I'll just not use this lib.

wade-cheng avatar Aug 20 '24 19:08 wade-cheng

To prevent this you can set THUMBNAIL_DEFAULT_STORAGE_ALIAS in settings (THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'default' for example) as workaround

Adding THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'default'` works for me. Thanks.

elielmartinsbr avatar Aug 23 '24 17:08 elielmartinsbr

To prevent this you can set THUMBNAIL_DEFAULT_STORAGE_ALIAS in settings (THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'default' for example) as workaround

Adding THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'default'` works for me. Thanks.

Thank you @Miketsukami and @elielmartinsbr. It also works for me. :)

Eraldo avatar Sep 10 '24 17:09 Eraldo