8000 fix: Placeholder page getter failed for unpublished pages by fsbraun · Pull Request #8115 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Placeholder page getter failed for unpublished pages #8115

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 5 commits into from
Jan 29, 2025

Conversation

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

Description

placeholder.page does not use the admin manager to retrieve a page object. This leads it to being None also for placeholders on pages which have no published content. This might lead to page-related placeholder configuration being ignored.

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

Bug Fixes:

  • Fix the placeholder page getter to correctly retrieve page objects for placeholders on unpublished pages by using the admin manager.

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

Reviewer's Guide by Sourcery

The pull request fixes the issue where the placeholder page getter fails for unpublished pages by changing the logic to use PageContent's admin manager for retrieving page objects, ensuring that placeholders on pages without published content are handled correctly.

Sequence diagram for placeholder page getter before and after fix

sequenceDiagram
    participant P as Placeholder
    participant PC as PageContent
    participant Page as Page

    rect rgb(240, 240, 240)
    Note over P,Page: Before Fix
    P->>Page: get(pagecontent_set__placeholders=self)
    alt Page exists and is published
        Page-->>P: Return page
    else Page doesn't exist or is unpublished
        Page-->>P: Return None
    end
    end

    rect rgb(220, 240, 220)
    Note over P,Page: After Fix
    P->>PC: admin_manager.filter(placeholders=self)
    PC->>P: Return PageContent
    P->>PC: Get associated page
    alt PageContent exists
        PC-->>P: Return page
    else PageContent doesn't exist
        PC-->>P: Return None
    end
    end
Loading

Class diagram showing the relationship between Placeholder, PageContent, and Page

classDiagram
    class Placeholder {
        -_page
        +page_getter()
    }
    class PageContent {
        +admin_manager
        +placeholders
        +page
    }
    class Page {
        +pagecontent_set
    }

    Placeholder "*" --> "1" PageContent : belongs to
    PageContent "*" --> "1" Page : belongs to
    note for Placeholder "Changed to use PageContent's admin_manager"
Loading

File-Level Changes

Change Details Files
Fix the page getter method to handle unpublished pages correctly.
  • Replaced the import of Page with PageContent from contentmodels.
  • Modified the page getter logic to use PageContent.admin_manager to filter placeholders.
  • Handled AttributeError instead of Page.DoesNotExist and Page.MultipleObjectsReturned.
cms/models/placeholdermodel.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.
  • 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 - here's some feedback:

Overall Comments:

  • Please remove the commented out code since it's no longer needed and clutters the file.
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 changed the title Fix: Placeholder page getter fails for unpublished pages fix: Placeholder page getter fails for unpublished pages Jan 22, 2025
@fsbraun fsbraun requested a review from a team January 27, 2025 23:50
@fsbraun fsbraun added needs to be backported Commits need to be backported 5.0 labels Jan 27, 2025
@fsbraun fsbraun changed the title fix: Placeholder page getter fails for unpublished pages fix: Placeholder page getter failed for unpublished pages Jan 28, 2025
@vinitkumar
Copy link
Member

@fsbraun Looks good. Let's get this merged. 🚀

@fsbraun fsbraun< 8000 /a> merged commit 4bcb4b4 into django-cms:develop-4 Jan 29, 2025
51 checks passed
@fsbraun fsbraun deleted the fix/page-getter branch January 29, 2025 12:01
fsbraun added a commit to fsbraun/django-cms that referenced this pull request Jan 29, 2025
…#8115)

* Fix: Placeholder page getter fails for unpublished pages

* Update cms/models/placeholdermodel.py

* Update cms/models/placeholdermodel.py
fsbraun added a commit that referenced this pull request Jan 30, 2025
)

* Fix: Placeholder page getter fails for unpublished pages

* Update cms/models/placeholdermodel.py

* Update cms/models/placeholdermodel.py
fsbraun added a commit that referenced this pull request Jan 30, 2025
* fix: Placeholder page getter failed for unpublished pages (#8115)

* Fix: Placeholder page getter fails for unpublished pages

* Update cms/models/placeholdermodel.py

* Update cms/models/placeholdermodel.py

* fix: Use correct `changed_date` of page content in sitemap (#8122)

* Sitemap returns changed_date for page content object

* Avoid prefetch by modifying the subquery

* Update tests for sitemap

* Update test_plugins.py

* Update test_page.py

---------

Co-authored-by: Fabian Braun <fsbraun@gmx.de>

* Update databases.txt

---------

Co-authored-by: Jacob Rief <jacob.rief@gmail.com>
fsbraun added a commit that referenced this pull request Feb 4, 2025
* fix: Placeholder page getter failed for unpublished pages (#8115)

* Fix: Placeholder page getter fails for unpublished pages

* Update cms/models/plac
72C0
eholdermodel.py

* Update cms/models/placeholdermodel.py

* fix: Allow frontend editing of page title fields (#8131)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 needs to be backported Commits need to be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0