Fix events coach/student 500 when member already has an event invitation - #2795
Merged
Conversation
`Invitation.create_or_find_by` in `find_invitation_and_redirect_to_event` returns an unsaved record (id/token nil) when the member already has an invitation for the event+role with attending nil, because the uniqueness validation fails but create_or_find_by only rescues RecordNotUnique. The subsequent `redirect_to event_invitation_path` then raises a UrlGenerationError for a missing token. Fall back to the existing persisted invitation when create_or_find_by returns an unpersisted record. Same fix as #2791 applied to the events path. Fixes #2794
mroderick
marked this pull request as ready for review
August 8, 2026 15:44
mroderick
force-pushed
the
fix/event-invitation-nil-token
branch
from
August 8, 2026 17:07
25a63fa to
0c8eef2
Compare
KimberleyCook
approved these changes
Aug 9, 2026
mroderick
enabled auto-merge
August 9, 2026 12:01
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.
Closes #2794
Summary
Fixes a 500 when a logged-in member clicks Coach/Student on an event where they already have an
Invitationrow for that event + role withattendingNULL.Related Rollbar items
EventsController#student, event 448 (virtual-open-day-8)EventsController#coach, event 448 (virtual-open-day-8)Both are the same defect triggered through the
studentandcoachactions respectively.Root cause
find_invitation_and_redirect_to_eventusedInvitation.create_or_find_by. In Rails 8.1,create_or_find_bycalls the non-bangcreate. When the uniqueness validation fails (row already exists), it returns an unpersisted record withtoken: nil. BecauseInvitation#to_paramreturnstoken, the subsequentredirect_to event_invitation_pathraisesActionController::UrlGenerationError. Same bug as #2790, on the events/Invitation path — #2791 only covered workshops.Fix
After
create_or_find_by, checkpersisted?. If not persisted, fall back toInvitation.find_by(event:, member:, role:)to return the existing row.Verification
GET #studentandGET #coachcovering:codebar_production_dumpfor both Rollbar items:virtual-open-day-8), Student rolevirtual-open-day-8), Coach role/events/virtual-open-day-8/invitation/:tokenURL.bundle exec rubocop app/controllers/events_controller.rb spec/controllers/events_controller_spec.rb— no offenses.Post-Deploy Monitoring & Validation
ActionController::UrlGenerationErrorwithcontroller: "invitations"andtoken: nilinEventsController#find_invitation_and_redirect_to_event.