Code bug
NoMethodError
undefined method 'start_date' for nil member_program_statuses.first.start_date ^^^^^^^^^^^
In one line
MemberProgram#duration crashes with a nil error when a member program has no status rows, and that breaks the whole member_programs index response.
Checked against the code
What happened
- `duration` calls `member_program_statuses.first.start_date` with no nil check.
- The member program that crashed has no member_program_statuses rows (or no active one when `active?` is true).
- One such record in the serialized list fails the whole index request.
- There were 10 events from 3 users over 13 days. That fits a few bad records, not a deploy problem. The code on releases/master is unchanged.
What to do next
- Code fix In app/models/member_program.rb, change MemberProgram#duration to return nil when no start date is found. Use `&.start_date` on both branches and `return unless start_date` before the subtraction.
- Query
Lists member programs with no status rows, which are the records that crash `duration`; check whether they are recent.
SELECT mp.id, mp.status, mp.program_id, mp.created_at FROM member_programs mp LEFT JOIN member_program_statuses mps ON mps.member_program_id = mp.id GROUP BY mp.id HAVING COUNT(mps.id) = 0 ORDER BY mp.created_at DESC LIMIT 50;
Queries are shown, never run. Check them before using them on production.
Ask a follow-up
Continues the same session, so it still remembers the error and the code it read.
Analysed 1 h ago · claude-sonnet-5-5 · $0.04