Skip to content

Commit

Permalink
Use the new STORAGES setting in Django 4.2
Browse files Browse the repository at this point in the history
In Django 4.2 the django.core.files.storage.get_storage_class() function is deprecated as well as the STATICFILES_STORAGE setting in favor of STORAGES["staticfiles"].

Use django.core.files.storage.storages to get the configured storage class for static files instead.

For Django versions prior to 4.2 keep using the django.core.files.storage.get_storage_class() function for backwards compatibility.

Fixes #1758
  • Loading branch information
radwon committed Apr 9, 2023
1 parent 5130f3c commit 6ca66fc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions debug_toolbar/panels/staticfiles.py
Expand Up @@ -3,7 +3,6 @@
from django.conf import settings
from django.contrib.staticfiles import finders, storage
from django.core.checks import Warning
from django.core.files.storage import get_storage_class
from django.utils.functional import LazyObject
from django.utils.translation import gettext_lazy as _, ngettext

Expand Down Expand Up @@ -53,7 +52,17 @@ class DebugConfiguredStorage(LazyObject):
"""

def _setup(self):
configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)
try:
# From Django 4.2 use django.core.files.storage.storages in favor
# of the deprecated django.core.files.storage.get_storage_class
from django.core.files.storage import storages

configured_storage_cls = storages["staticfiles"].__class__
except ImportError:
# Backwards compatibility for Django versions prior to 4.2
from django.core.files.storage import get_storage_class

configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)

class DebugStaticFilesStorage(configured_storage_cls):
def __init__(self, collector, *args, **kwargs):
Expand Down

0 comments on commit 6ca66fc

Please sign in to comment.