Skip to content

Renormalize new contact/responsible-party items on publish#613

Open
Bhavatu wants to merge 1 commit into
mainfrom
fix/contact-person-renormalize-new-items
Open

Renormalize new contact/responsible-party items on publish#613
Bhavatu wants to merge 1 commit into
mainfrom
fix/contact-person-renormalize-new-items

Conversation

@Bhavatu

@Bhavatu Bhavatu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

When a revision adds a new (pk=None) ActionContactPerson or ActionResponsibleParty for a person/org already attached to the live action under another pk, modelcluster's commit() runs the INSERT before the existing row's wrapped_id is rewritten, violating the unique (action, person) / (action, organization) constraint.
The detection loop in _renormalize_pks_for_unique_constraint skipped pk=None targets, so the renormalize step never ran. Detect them too and let the existing renormalize logic reassign the new item to the holding row's pk.

Fixes WATCH-BACKEND-5WW

Screenshots/Videos (if applicable)

Add screenshots or videos demonstrating the changes if applicable.

Related issue

https://sentry.kausal.tech/organizations/kausal/issues/16934/?project=3&query=is%3Aunresolved&referrer=issue-stream&sort=new

Requirements, dependencies and related PRs

Describe or link possible requirements, dependencies and related PRs here

Additional Notes

Any additional information that reviewers should know about this PR.


✅ Pre-Merge Checklist

Type of Change

  • Set the PR's label to match the nature of this change

Testing

  • Built Unit tests (unit tests added/updated)
  • Built E2E tests (if applicable. E2E tests added/updated)
  • Authorization is tested (permissions and access controls verified)
  • Manually tested locally (functionality verified)
    Manual testing instructions
    If feature requires manual testing by reviewer, you can provide instructions here.

Internationalization & Accessibility

  • [-] New strings are translatable (all user-facing text uses i18n)
  • [-] Accessibility standards met (WCAG compliance, screen reader support)

Integrations (if applicable)

If there are model changes to models which use any of the features below, verify the new models work together with the features.
For example, when adding a new model, verify the new model instances are copied when copying a plan.

  • Moderation integration implemented
  • Reporting integration implemented
  • Copy plan feature integration implemented
  • Umbrella plan structure integration implemented

Dependencies

  • [-] Dependencies are merged (if applicable. If the change depends on other PRs e.g. kausal_common)

@Bhavatu Bhavatu added the Bug fix Bug fix (non-breaking change which fixes an issue) label Jun 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9030b8d80d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread actions/models/action.py
@kausal-code-coverage

kausal-code-coverage Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
actions/models/action.py 66.66% 1 Missing and 1 partial ⚠️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #613   +/-   ##
=======================================
  Coverage   62.59%   62.60%           
=======================================
  Files         386      386           
  Lines       40890    40892    +2     
  Branches     5230     5231    +1     
=======================================
+ Hits        25595    25599    +4     
+ Misses      13685    13684    -1     
+ Partials     1610     1609    -1     
Flag Coverage Δ
e2e-tests 8.62% <0.00%> (-0.01%) ⬇️
unittests 59.92% <66.66%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
actions/models/action.py 75.24% <66.66%> (+0.24%) ⬆️

Impacted file tree graph

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

When a revision adds a new (pk=None) ActionContactPerson or
ActionResponsibleParty for a person/org already attached to the live
action under another pk, modelcluster's commit() runs the INSERT before
the existing row's wrapped_id is rewritten, violating the unique
(action, person) / (action, organization) constraint. The detection
loop in _renormalize_pks_for_unique_constraint skipped pk=None targets,
so the renormalize step never ran. Detect them too and let the existing
renormalize logic reassign the new item to the holding row's pk.

Fixes WATCH-BACKEND-5WW

Surface IntegrityError when revision content has duplicate persons/orgs

If the renormalization input itself contains two entries for the same
person/organization, the unique constraint is already violated by the
payload. Bail out of renormalization in that case so the IntegrityError
surfaces, instead of silently collapsing both target entries onto the
same DB pk (which would let one role/order overwrite the other).
@Bhavatu Bhavatu force-pushed the fix/contact-person-renormalize-new-items branch from c0943ca to 02e0a11 Compare June 5, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix Bug fix (non-breaking change which fixes an issue)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant