Tolerate concurrent built-in callout seeding (fix RecordNotUnique)#2001
Merged
Conversation
BuiltinCallouts#seed does a check-then-insert, and it runs on GET requests (edit, sample_ticket) that write. Two concurrent requests both see a built-in as missing (the uniqueness validation SELECT passes for both) and both INSERT, so the DB unique index on [event_id, builtin_key] rejects the loser with RecordNotUnique. Seeding is idempotent by design, so rescue the constraint violation and skip the row rather than crashing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
maebeale
marked this pull request as ready for review
July 15, 2026 19:07
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.
🤖 suggested review level: 3 Read 📖 small contained fix to one service's insert path, covered by a new spec
What is the goal of this PR and why is this important?
ActiveRecord::RecordNotUnique: Duplicate entry '11-handouts' for ...index_registration_ticket_callouts_on_event_id_and_builtin_key.BuiltinCallouts#seedcheck-then-inserts and runs on GET requests that write (edit,sample_ticket). Two concurrent requests both see a built-in as missing (theuniquenessvalidation SELECT passes for both), both INSERT, and the DB unique index rejects the loser.How did you approach the change?
createnow rescuesActiveRecord::RecordNotUnique, resets the association (drops the failed in-memory row so the editor never renders a phantom), and skips that built-in.handoutsinsert) and assertsseeddoesn't raise and the other seven built-ins still materialize.Anything else to add?