8000 fix: Replaced `languages` field from `Page` which used to become inconsistent by fsbraun · Pull Request #8080 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Replaced languages field from Page which used to become inconsistent #8080

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
Nov 27, 2024

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Nov 14, 2024

Description

This PR removes the ambiguous languages field from the Page model:

Originally, it contained a chained string of available Title objects (which is of course redundant) and was maintained to save database hits. With django CMS 4 its use does not save database hits any more. The same information is available through the new PageUrl model, which needs to be unique by page and language.

Fixes #8019
Fixes #7838

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

Remove the languages field from the Page model to address inconsistencies and redundancy issues. Replace it with a more reliable mechanism using the PageUrl model, which ensures unique page-language combinations. Deprecate related methods and update the codebase to reflect these changes, including adjustments to tests and migrations.

Bug Fixes:

  • Fix inconsistencies in the languages field of the Page model by removing it.

Enhancements:

  • Deprecate and replace the languages attribute and related methods with a more reliable mechanism using PageUrl.

@fsbraun fsbraun marked this pull request as ready for review November 14, 2024 07:00
@fsbraun fsbraun requested a review from jrief November 14, 2024 07:00
@fsbraun
Copy link
Member Author
fsbraun commented Nov 20, 2024

@sourcery-ai review

Copy link
Contributor
sourcery-ai bot commented Nov 20, 2024

Reviewer's Guide by Sourcery

This PR removes the languages field from the Page model and refactors related functionality to rely on PageUrl model instead. The implementation focuses on removing redundant data storage and improving data consistency by enforcing unique constraints on page URLs per language.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Removed redundant languages field from Page model
  • Removed languages CharField from Page model
  • Added database migration to remove the field
  • Added unique constraint on (language, page) in PageUrl model
cms/models/pagemodel.py
cms/migrations/0039_remove_page_languages_alter_pageurl_unique_together.py
Refactored language-related methods to use PageUrl model
  • Deprecated languages property with warning
  • Updated get_languages() method to use content cache
  • Deprecated remove_language() and update_languages() methods
  • Optimized URL caching mechanism
  • Refactored get_path() and get_slug() to use common get_url_obj() method
cms/models/pagemodel.py
Updated dependent code to work without languages field
  • Removed language field updates from content creation
  • Modified page content deletion to clear caches
  • Updated menu system to work without languages field
  • Added performance test for page queries
cms/api.py
cms/admin/pageadmin.py
cms/cms_menus.py
cms/tests/test_views.py
menus/utils.py

Assessment against linked issues

Issue Objective Addressed Explanation
#8019 Fix inconsistency in Page model's languages field
#7838 Add unique_together constraint on PageUrl model to prevent duplicate entries for the same page/language combination
#7838 Fix issue where multiple PageUrl objects can exist for the same page/language causing MultipleObjectsReturned exceptions

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: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 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 November 22, 2024 22:43
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.

Looks good to me. Let's get this merged.

@fsbraun fsbraun merged commit 1031d20 into django-cms:develop-4 Nov 27, 2024
51 checks passed
@fsbraun fsbraun deleted the fix/page-languages branch November 27, 2024 06:49
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.

[BUG] Field languages in model Page may be inconsistent [BUG] Model PageUrl should add constraint unique_together
2 participants
0