Skip to content

Commit

Permalink
fix #59: cannot import name get_storage_class (Django 5.1) (#60)
Browse files Browse the repository at this point in the history
* fix #59: cannot import name `get_storage_class` (Django 5.1)

The `get_storage_class` function has been removed in Django 5.1

https://docs.djangoproject.com/en/5.1/releases/5.1/

* Use settings.STORAGES["default"] introduced in Django 5.0

Adjusted storage class retrieval to support the new STORAGES structure
introduced in Django 5.0. The code now checks for the presence of a
default storage configuration in settings, reverting to the previous
DEFAULT_FILE_STORAGE setting for compatibility with earlier versions.
This change maintains compatibility with both Django < 5.0 and >= 5.0
environments.

* django_settings
  • Loading branch information
ecarrara authored Aug 23, 2024
1 parent 59c743c commit 4dc6986
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions django_migrations_ci/management/commands/migrateci.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from pathlib import Path

from django.core.files.storage import get_storage_class
from django.conf import settings as django_settings
from django.core.management.base import BaseCommand, CommandError
from django.utils.module_loading import import_string

try:
from django.test.runner import get_max_test_processes # type: ignore[attr-defined]
Expand Down Expand Up @@ -71,8 +72,14 @@ def handle(
elif parallel is not None:
parallel = int(parallel)

storage_class = get_storage_class(storage_class)
default_storage_class = get_storage_class(
if hasattr(django_settings, "STORAGES") and "default" in django_settings.STORAGES:
default_file_storage = django_settings.STORAGES["default"].get("BACKEND", "django.core.files.storage.FileSystemStorage")
else:
# Django < 5.0
default_file_storage = getattr(django_settings, "DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage")

storage_class = import_string(storage_class or default_file_storage)
default_storage_class = import_string(
"django.core.files.storage.FileSystemStorage",
)
if issubclass(storage_class, default_storage_class):
Expand Down

0 comments on commit 4dc6986

Please sign in to comment.