Commit 4fc401b
fix: Prevent uniqueness validation error when updating case contact types
Fixes Bugsnag error "Validation failed: Case contact has already been taken"
(Error URL: https://api.bugsnag.com/projects/5f370b68136a4b0010d15364/events/6924fd6f015b929d46570000)
The issue occurred when updating case contacts with contact types. The
remove_unwanted_contact_types method used contact_types.clear which marks
records for deletion in memory but doesn't immediately execute DELETE
statements. When the subsequent update attempted to create new join records,
the old records still existed in the database, triggering the uniqueness
validation on CaseContactContactType.
Changed to use destroy_all which immediately deletes records from the
database, ensuring old contact type associations are fully removed before
new ones are created.
Added regression test to prevent this issue from recurring.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent df6787f commit 4fc401b
File tree
2 files changed
+14
-1
lines changed- app/controllers/case_contacts
- spec/requests/case_contacts
2 files changed
+14
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
237 | 250 | | |
238 | 251 | | |
239 | 252 | | |
| |||
0 commit comments