Skip to content

fix: Remove unnecessary _original_manager usage from toolbar #477

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 1 commit into from
Jul 31, 2025

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Jul 31, 2025

Description

The toolbar accesses _original_manager which is the style of djangocms-versioning<2. For consistency and unnecessary code repetition, the objects manager should be used for getting published content.

Related resources

  • #...
  • #...

Checklist

  • I have opened this pull request against master
  • 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 #workgroup-pr-review on
    Slack to find a “pr review buddy” who is going to review my pull request.

Summary by Sourcery

Use the default PageContent manager instead of the outdated _original_manager when fetching published content in the CMS toolbar

Enhancements:

  • Replace PageContent._original_manager.filter with PageContent.objects.filter in _get_published_page_version
  • Add select_related("page") to optimize the published content query

Copy link
Contributor

sourcery-ai bot commented Jul 31, 2025

Reviewer's Guide

Update toolbar content lookup to use Django’s default manager and streamline the published page version query.

Class diagram for PageContent manager usage update

classDiagram
    class PageContent {
        +objects: Manager
        -_original_manager: Manager (removed from usage)
    }
    class cms_toolbars {
        _get_published_page_version()
    }
    PageContent <.. cms_toolbars : used by
Loading

File-Level Changes

Change Details Files
Switch from the legacy _original_manager to the default objects manager and simplify the query
  • Replace PageContent._original_manager.filter with PageContent.objects.filter
  • Remove the versions__state=PUBLISHED filter
  • Chain select_related('page') and first() to return a single version
djangocms_versioning/cms_toolbars.py

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@fsbraun fsbraun requested a review from vinitkumar July 31, 2025 07:36
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!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `djangocms_versioning/cms_toolbars.py:246` </location>
<code_context>
             return

-        return PageContent._original_manager.filter(
-            page=self.page, language=language, versions__state=PUBLISHED
+        return PageContent.objects.filter(
+            page=self.page, language=language
         ).select_related("page").first()

</code_context>

<issue_to_address>
Removing the versions__state=PUBLISHED filter may return non-published versions.

Please confirm that returning PageContent objects in any state is intentional, as this may affect logic expecting only published versions.
</issue_to_address>

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 changed the title fix: Remove _original_manager usage (outdated code style) fix: Remove unnecessary _original_manager usage from toolbar Jul 31, 2025
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.66%. Comparing base (a132204) to head (c3a65cb).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   90.55%   93.66%   +3.10%     
==========================================
  Files          72       76       +4     
  Lines        2732     2699      -33     
  Branches      322        0     -322     
==========================================
+ Hits         2474     2528      +54     
+ Misses        182      171      -11     
+ Partials       76        0      -76     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@vinitkumar vinitkumar left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

@fsbraun fsbraun merged commit d0c928c into master Jul 31, 2025
78 of 80 checks passed
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