Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Mar 28, 2025

Description

An initial value given to the LinkFormField needs to be recognized.

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

Fix initial value handling for LinkFormField to correctly decode and prepare initial values for internal and external links

Bug Fixes:

  • Ensure LinkFormField correctly processes initial values for both internal and external link types

CI:

  • Add test configurations for Django 5.2 with different CMS versions

Tests:

  • Add test cases to verify initial value handling for internal and external links in LinkFormField
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 28, 2025

Reviewer's Guide by Sourcery

This pull request fixes an issue where initial values provided to the LinkFormField were not being correctly decoded. It adds test cases to verify the fix, and updates the CI configuration to include Django 5.2 and CMS 5.0.

Sequence diagram for LinkFormField initialization

sequenceDiagram participant LinkFormField LinkFormField->>LinkFormField: __init__(*args, **kwargs) alt isinstance(self.initial, dict) LinkFormField->>LinkFormField: prepare_value(self.initial) LinkFormField-->>LinkFormField: self.initial = prepared value end 
Loading

Updated class diagram for LinkFormField

classDiagram class LinkFormField { -initial: dict +__init__(*args, **kwargs) +prepare_value(value: dict) list[str | None] +to_python(value: list[str | None]) dict -_get_pos(link_type) int } note for LinkFormField "Initial value is now prepared in __init__" 
Loading

File-Level Changes

Change Details Files
Ensured that the LinkFormField correctly processes initial values for both internal and external link types.
  • Modified LinkFormField to prepare initial values correctly before form rendering.
  • Added a check to see if the initial value is a dictionary, and if so, calls prepare_value to format the initial value.
djangocms_link/fields.py
Added test cases to verify initial value handling for internal and external links in LinkFormField.
  • Added test_form_field_initial_works_internal to verify initial value handling for internal links.
  • Added test_form_field_initial_works_external to verify initial value handling for external links.
tests/test_fields.py
Updated CI workflows to support Django 5.2 and CMS 5.0.
  • Added dj52_cms41.txt and dj52_cms50.txt to the test matrix in .github/workflows/test.yml.
  • Added dj52_cms41.txt and dj52_cms50.txt files to the repository.
.github/workflows/test.yml
tests/requirements/dj52_cms41.txt
tests/requirements/dj52_cms50.txt
Adjusted migration tests to account for Django 5.2.
  • Skipped migration tests for Django version >= 5.2.
tests/test_migrations.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@codecov
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.70%. Comparing base (29f546d) to head (9eb7b88).
Report is 3 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@ ## master #239 +/- ## ========================================== + Coverage 95.35% 95.70% +0.34%  ========================================== Files 27 28 +1 Lines 668 675 +7 Branches 86 87 +1 ========================================== + Hits 637 646 +9  + Misses 14 13 -1  + Partials 17 16 -1 

☔ 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.
@fsbraun fsbraun marked this pull request as ready for review March 28, 2025 22:06
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:

  • The changes to the test matrix look good, but it might be worth adding a comment explaining why Django 5.2 is excluded in test_migrations.py.
  • Consider adding a test case with an empty initial value to ensure that case is handled correctly.
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 3a649da into master Mar 31, 2025
41 checks passed
@fsbraun fsbraun deleted the fix/initial branch March 31, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants