fix(invitations): prevent duplicate workshop invitation emails#2577
Merged
till merged 1 commit intocodebar:masterfrom Apr 16, 2026
Merged
fix(invitations): prevent duplicate workshop invitation emails#2577till merged 1 commit intocodebar:masterfrom
till merged 1 commit intocodebar:masterfrom
Conversation
971c460 to
77323a2
Compare
till
approved these changes
Apr 16, 2026
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.
Summary
Fixes a bug where re-running workshop invitation batches would send duplicate emails to members who had already been invited.
Problem Analysis
What Was Happening
When invitation batches were triggered multiple times for the same workshop:
WorkshopInvitation.find_or_create_bywould find existing invitations (not create new ones)logger.log_skippedexisted in the codebase but was never calledReal-World Evidence
Brighton Chapter - Workshop #3679 (April 21, 2026):
The Issue:
Root Cause
The code pattern in all 4 invitation methods:
When an invitation already existed,
find_or_create_byreturned it, and the code treated it the same as a newly created invitation.Solution
1. Track New vs Existing Invitations
Changed
create_invitationfromfind_or_create_bytofind_or_initialize_by+save!:2. Detect Duplicates and Skip Emails
Added
previously_new_record?checks in all invitation methods:3. DRY Refactor
Extracted common logic to
invite_membershelper:Changes
Files Modified
app/models/concerns/workshop_invitation_manager_concerns.rbinvite_membershelperpreviously_new_record?detectionlog_skippedcalls for existing invitationsspec/models/invitation_manager_spec.rb#create_invitationunit tests for new vs existing behaviorspec/support/shared_examples/behaves_like_sending_workshop_emails.rbfind_or_create_bytofind_or_initialize_byTesting
All tests pass:
previously_new_record? = truepreviously_new_record? = falseImpact
Immediate Benefits
invitation_logsFuture Benefits
Verification
To verify this fix works:
Related
skipped_count = 0anomaly identified in production logs