Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Sep 15, 2025

…esent in the db

Description

Related resources

  • #...
  • #...

Checklist

Summary by Sourcery

Bug Fixes:

  • Add explicit check for obj_placeholder_field in migration forward to prevent failures when placeholder objects are not present

Copy link
Contributor

sourcery-ai bot commented Sep 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enhance migration 0033 by tightening the conditional in the forwards function to update placeholder associations only when an existing placeholder object is present, preventing failures on missing records.

Class diagram for updated placeholder association logic in migration 0033

classDiagram
    class PlaceholderField {
        +content_type_id
        +object_id
        +save()
    }
    class ContentType {
        +pk
    }
    class Object {
        +pk
    }
    PlaceholderField -- ContentType : content_type_id
    PlaceholderField -- Object : object_id
Loading

Flow diagram for conditional update in migration 0033

flowchart TD
    A["Iterate over objects"] --> B["Check if placeholder object exists"]
    B -- Yes --> C["Create new PlaceholderField with content_type_id and object_id"]
    B -- No but obj_placeholder_field exists --> D["Update obj_placeholder_field with content_type_id and object_id"]
    D --> E["Save obj_placeholder_field"]
Loading

File-Level Changes

Change Details Files
Guard placeholder updates with an explicit existence check
  • Replaced else: with elif obj_placeholder_field: in the forwards migration to skip updates when no placeholder object exists
cms/migrations/0033_placeholder_source_data_migration.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 changed the title fix: Migration 0033 failed when empty placeholder objects were not pr… fix: Migration 0033 failed when empty placeholder objects were not present in the db Sep 15, 2025
@fsbraun fsbraun added the backport Commits are being back ported label Sep 15, 2025
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 there - 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> `cms/migrations/0033_placeholder_source_data_migration.py:42` </location>
<code_context>
                             object_id=obj.pk,
                         )
-                    else:
+                    elif obj_placeholder_field:
                         obj_placeholder_field.content_type_id = cur_ct_obj.pk
                         obj_placeholder_field.object_id = obj.pk
</code_context>

<issue_to_address>
Consider whether the new elif branch could mask cases where obj_placeholder_field is falsy but not None.

Changing to 'elif obj_placeholder_field:' means the block only runs for truthy values. If valid cases exist where obj_placeholder_field is falsy, this logic may skip updates. Please verify that all necessary cases are still handled.
</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.

@@ -39,7 +39,7 @@ def forwards(apps, schema_editor):
content_type_id=cur_ct_obj.pk,
object_id=obj.pk,
)
else:
elif obj_placeholder_field:
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Consider whether the new elif branch could mask cases where obj_placeholder_field is falsy but not None.

Changing to 'elif obj_placeholder_field:' means the block only runs for truthy values. If valid cases exist where obj_placeholder_field is falsy, this logic may skip updates. Please verify that all necessary cases are still handled.

Copy link

👋 Hi there!

Please remember to MERGE COMMIT pull requests from main!

Do not SQUASH commits to preserve history for the changelog.

@fsbraun fsbraun merged commit 7ec333d into release/5.0.x Sep 15, 2025
71 checks passed
@fsbraun fsbraun deleted the chore/bp-migration-33 branch September 15, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Commits are being back ported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant