8000 fix: Remove deprecated `get_storage_class` import from `cms.utils` by fsbraun · Pull Request #8102 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Remove deprecated get_storage_class import from cms.utils #8102

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

Merged
merged 8 commits into from
Jan 8, 2025

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Jan 2, 2025

Description

get_storage_class has been deprecated since Django 4.2 and was removed in Django 5.1.

cms.utils since before Django CMS 2 contained a lazy configured_storage object which is not used by Django CMS, but might be used by legacy installations.

To fix the incompatibility issue, this PR moves the import into the lazy configured_storage object, removing the import from cms.utils but keeping the configured_storage object available for backwards compatibility.

The configured_storage object should not be used with Django 5.1, but will technically work and use Django's django.utils.module_loading.import_string. The utility function has already been removed already in django CMS 4.0

fixes #8101

Related resources

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined the channel #pr-reviews on our Discord Server to find a “pr review buddy” who is going to review my pull request.

Summary by Sourcery

Resolve compatibility issue with Django 5.1 by addressing the removal of the deprecated get_storage_class import.

Bug Fixes:

  • Fix incompatibility with Django 5.1 caused by the removal of get_storage_class. The import was moved into the lazy configured_storage object to maintain backwards compatibility.

Enhancements:

  • Move the deprecated < 8000 code class="notranslate">get_storage_class import into the lazy configured_storage object.

CI:

  • Add Django 5.1 to the CI test matrix.

Copy link
Contributor
sourcery-ai bot commented Jan 2, 2025

Reviewer's Guide by Sourcery

This PR resolves a Django version incompatibility issue by addressing the deprecation and subsequent removal of the get_storage_class utility. It modifies the cms.utils module to lazily import get_storage_class within the configured_storage object, ensuring backward compatibility while accommodating newer Django versions. Additionally, the PR updates test configurations to include Django 5.1.

Sequence diagram for updated storage class initialization

sequenceDiagram
    participant ConfiguredStorage
    participant LazyObject
    participant ImportString
    participant Settings

    ConfiguredStorage->>LazyObject: _setup()
    LazyObject->>ImportString: import_string(STATICFILES_STORAGE)
    ImportString->>Settings: getattr(settings, 'STATICFILES_STORAGE', default_storage)
    Settings-->>ImportString: storage_class_path
    ImportString-->>LazyObject: StorageClass
    LazyObject->>LazyObject: instantiate StorageClass()
    LazyObject-->>ConfiguredStorage: _wrapped = StorageInstance
Loading

Class diagram for ConfiguredStorage implementation

classDiagram
    class LazyObject {
        +_setup()
        +_wrapped
    }
    class ConfiguredStorage {
        +_setup()
    }
    ConfiguredStorage --|> LazyObject
    note for ConfiguredStorage "Changed to use import_string
instead of get_storage_class"
Loading

File-Level Changes

Change Details Files
Move get_storage_class import into configured_storage object
  • Import import_string from django.utils.module_loading.
  • Use import_string to dynamically import the storage class specified in settings.STATICFILES_STORAGE or fall back to the default storage if not configured.
  • Remove the direct import of get_storage_class from cms.utils.
cms/utils/__init__.py
Update Django version compatibility
  • Restrict Django version to be less than 5.2 in setup.cfg to address the incompatibility issue.
setup.cfg
Add Django 5.1 to test matrix
  • Include Django 5.1 in the test matrix within the GitHub workflow configuration file.
  • Add a requirements file test_requirements/django-5.1.txt for Django 5.1 testing dependencies.
.github/workflows/test.yml
test_requirements/django-5.1.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#8101 Fix the ImportError caused by the removal of get_storage_class in Django 5.1
#8101 Maintain backwards compatibility for legacy installations using configured_storage
#8101 Update Django version compatibility to reflect the changes in Django 5.1

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fsbraun - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun fsbraun requested a review from a team January 2, 2025 19:07
@fsbraun fsbraun marked this pull request as draft January 2, 2025 19:14
Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fsbraun - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a deprecation warning in ConfiguredStorage._setup() to indicate that configured_storage won't work with Django 5.1+
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun fsbraun merged commit 31f80c5 into release/3.11.x Jan 8, 2025
85 checks passed
@fsbraun fsbraun deleted the fix/get-storage-class-import branch January 8, 2025 07:44
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

Successfully merging this pull request may close these issues.

2 participants
0