Renormalize new contact/responsible-party items on publish#613
Open
Bhavatu wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
💡 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".
Codecov Report❌ Patch coverage is
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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).
c0943ca to
02e0a11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Testing
Manual testing instructions
If feature requires manual testing by reviewer, you can provide instructions here.Internationalization & Accessibility
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.
Dependencies