fix: make sponsor coach spots nil-safe - #2787
Merged
Merged
Conversation
mroderick
marked this pull request as ready for review
August 6, 2026 08:01
KimberleyCook
approved these changes
Aug 9, 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.
Problem
Linked to #2500. The admin sponsor show page returned an HTTP 500 for some sponsor records.
Sponsor#coach_spotsdidnumber_of_coaches || (seats / 2.0).round, which raisesNoMethodError: undefined method '/' for nilwhen bothnumber_of_coachesandseatsare nil. The show view calls this unconditionally, so any incomplete record crashes.The #1794 fix (adding presence validations + HTML5
required) prevents new bad rows, but pre-existing records can still hold nil values, socoach_spotsremains crash-prone.Change
Make
coach_spotsnil-safe: returnnumber_of_coacheswhen present, else half the seats rounded, elsenilinstead of raising.Tests
Added three
#coach_spotscases tospec/models/sponsor_spec.rb. The nil-both case fails on the old implementation and passes with this fix.Database analysis
Checked the
codebar_dumpPostgres database for records that would trigger this crash. Querying forsponsorsrows whereseats IS NULL OR number_of_coaches IS NULLreturned 0 rows across all 751 sponsors. The broken records referenced in #2500 (IDs 1539 and 1540) are absent from the dump — only the valid1541(BDO UK, seats 0 / coaches 0) survives — so the bad rows appear to have already been removed in production. No data cleanup is required. The0values on remaining rows are valid (validation allows>= 0), so this fix is defensive hardening against recurrence through any non-controller data path.Note: the "duplicate sponsor on update" aspect of #2500 was not reproducible — no code path in the update/create actions creates a new Sponsor row.