Skip to content

Commit

Permalink
Replace deprecated get_storage_class with storages
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw committed Dec 30, 2023
1 parent f24f055 commit b890cdb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from uuid import uuid4

import sqlparse
from django.core.files.storage import get_storage_class
from django.conf import settings
from django.db import models, transaction
from django.db.models import (
BooleanField,
Expand All @@ -25,7 +25,20 @@
from silk.config import SilkyConfig
from silk.utils.profile_parser import parse_profile

silk_storage = get_storage_class(SilkyConfig().SILKY_STORAGE_CLASS)()
try:
# New in Django 4.2
from django.core.files.storage import storages
from django.core.files.storage.handler import InvalidStorageError
try:
silk_storage = storages['SILKY_STORAGE']
except InvalidStorageError:
from django.utils.module_loading import import_string
storage_class = SilkyConfig().SILKY_STORAGE_CLASS or settings.DEFAULT_FILE_STORAGE
silk_storage = import_string(storage_class)()
except ImportError:
# Deprecated since Django 4.2, Removed in Django 5.1
from django.core.files.storage import get_storage_class
silk_storage = get_storage_class(SilkyConfig().SILKY_STORAGE_CLASS)()


# Seperated out so can use in tests w/o models
Expand Down

0 comments on commit b890cdb

Please sign in to comment.