Skip to content

Tolerate concurrent built-in callout seeding (fix RecordNotUnique)#2001

Merged
maebeale merged 1 commit into
mainfrom
maebeale/fix-duplicate-callout-key
Jul 15, 2026
Merged

Tolerate concurrent built-in callout seeding (fix RecordNotUnique)#2001
maebeale merged 1 commit into
mainfrom
maebeale/fix-duplicate-callout-key

Conversation

@maebeale

Copy link
Copy Markdown
Collaborator

🤖 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?

  • Fixes a Honeybadger error: ActiveRecord::RecordNotUnique: Duplicate entry '11-handouts' for ...index_registration_ticket_callouts_on_event_id_and_builtin_key.
  • BuiltinCallouts#seed check-then-inserts and runs on GET requests that write (edit, sample_ticket). Two concurrent requests both see a built-in as missing (the uniqueness validation SELECT passes for both), both INSERT, and the DB unique index rejects the loser.

How did you approach the change?

  • Seeding is already idempotent by design, so create now rescues ActiveRecord::RecordNotUnique, resets the association (drops the failed in-memory row so the editor never renders a phantom), and skips that built-in.
  • Added a spec that simulates the race window (in-memory checks pass, DB rejects the handouts insert) and asserts seed doesn't raise and the other seven built-ins still materialize.

Anything else to add?

  • This is a read path that writes; a larger follow-up could move seeding to event create/publish only. Out of scope here.

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>
Copilot AI review requested due to automatic review settings July 15, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@maebeale
maebeale marked this pull request as ready for review July 15, 2026 19:07
@maebeale
maebeale merged commit 14f372e into main Jul 15, 2026
3 checks passed
@maebeale
maebeale deleted the maebeale/fix-duplicate-callout-key branch July 15, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants