Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected RemovedInDjango51Warning due to the import of get_storage_class #115

Closed
JMSoler7 opened this issue Feb 19, 2024 · 3 comments
Closed

Comments

@JMSoler7
Copy link
Contributor

This method from the django.core.files.storage module is deprecated as of Django 5.1.

It's easy to reproduce; simply define a custom IMPORT_EXPORT_CELERY_STORAGE in the config settings and reload the application:

/app/.venv/lib/python3.11/site-packages/import_export_celery/fields.py:10: RemovedInDjango51Warning: django.core.files.storage.get_storage_class is deprecated in favor of using django.core.files.storage.storages.
    storage_class = get_storage_class(settings.IMPORT_EXPORT_CELERY_STORAGE)

Upon inspecting the Django documentation (https://docs.djangoproject.com/en/5.0/ref/files/storage/#django.core.files.storage.get_storage_class), there is an explanation to use storages (https://docs.djangoproject.com/en/5.0/ref/files/storage/#django.core.files.storage.storages) instead of the get_storage_class method.

@timthelion
Copy link
Member

Can this be fixed in a backwards compatible fashion?

@JMSoler7
Copy link
Contributor Author

@timthelion I'm going to create a pull request in a few minutes which fits with all versions 😃

JMSoler7 added a commit to JMSoler7/django-import-export-celery that referenced this issue Feb 19, 2024
…modules instead of deprecated method

In Django documentation we can see that get_storage_class is deprecated in Django 5.1 and later.

https://docs.djangoproject.com/en/5.0/ref/files/storage/#django.core.files.storage.get_storage_class

Recommendation of Django is to use storages instead of get_storage_class. This leads to specify
this file storage backend in STORAGES config settings instead of a new config variable.

This commit allows also to keep using custom storage classe from older verions (4.2 and earlier) and
prevents to crash when invalid storage class is provided, using the default one.

Solves auto-mat#115
@PetrDlouhy
Copy link
Contributor

@JMSoler7 The logic of the PR seems to me to be quite harmful. I have written a comment on the PR, but there are other problems:

  • Switching to default storage when InvalidStorageError could lead to very unexpected behavior when there is some problem with the storage. I don't think it is equivalent with defaulting to default storage.
  • I don't think the code is backward compatible with applications not using the new STORAGES settings since settings.STORAGES.get("IMPORT_EXPORT_CELERY_STORAGE")["BACKEND"] will throw error if STORAGES are not used.

PetrDlouhy added a commit that referenced this issue May 22, 2024
PetrDlouhy added a commit that referenced this issue May 22, 2024
PetrDlouhy added a commit that referenced this issue May 23, 2024
PetrDlouhy added a commit that referenced this issue May 24, 2024
PetrDlouhy added a commit that referenced this issue May 24, 2024
PetrDlouhy added a commit that referenced this issue May 24, 2024
PetrDlouhy added a commit that referenced this issue May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants