[4.x] Fix duplicate entry error when updating TenantPivot columns#1469
Conversation
… resource Regression test for #1467
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds docblock clarifications in ChangesResource syncing docs and regression test
Estimated code review effort: 1 (Trivial) | ~4 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Use created() instead of saved() in TriggerSyncingEvents so that updating pivot columns no longer attempts to attach. Attaching re-created the tenant resource and caused a duplicate entry error (detaching already uses deleting(), so using created() is more consistent with that anyway)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1469 +/- ##
=========================================
Coverage 86.37% 86.37%
Complexity 1200 1200
=========================================
Files 186 186
Lines 3524 3524
=========================================
Hits 3044 3044
Misses 480 480 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The comment said an exception is thrown but not how -- it happens indirectly via findCentralResource() -> getResourceClass(). Also added a @throws annotation to getCentralResourceAndTenant().
|
@coderabbitai full review |
✅ Action performedFull review finished. |
TriggerSyncingEventsregistered the pivot attach listener onsaved, which fires on both inserts and updates. So updating pivot columns on aTenantPivot(e.g. viaupdateExistingPivot()) re-ran the attach flow and tried to create the tenant resource again, causing a duplicate entry error.Switched the listener to
createdso we only attach when the pivot record is first created (detaching already usesdeleting, so usingcreatedmakes things a bit more consistent).Added a regression test before the fix (5e3eb43). The fix (d2fb4bc) then made the test pass.
Also improved the
savinglistener's comment a bit so that it's clear where the "central resource not available" exception actually comes from, since that wasn't obvious (also added the@throwsannotation togetCentralResourceAndTenant()).Closes #1467
Summary by CodeRabbit