Skip to content

fix: handle nil paginated in fetch_upcoming_events and fetch_past_events#2586

Merged
mroderick merged 1 commit intocodebar:masterfrom
mroderick:fix/nil-group-by
Apr 23, 2026
Merged

fix: handle nil paginated in fetch_upcoming_events and fetch_past_events#2586
mroderick merged 1 commit intocodebar:masterfrom
mroderick:fix/nil-group-by

Conversation

@mroderick
Copy link
Copy Markdown
Collaborator

@mroderick mroderick commented Apr 22, 2026

Summary

  • Fixes NoMethodError: undefined method 'group_by' for nil when /events/upcoming or /events/past is accessed with no events or an out-of-bounds page number

Root Cause

In EventsController#fetch_upcoming_events and fetch_past_events, the code collects events from Workshops, Meetings, and Events, sorts them, and then calls pagy to paginate. However:

  1. When sorted is empty (no upcoming/past events), paginated can be nil
  2. When requesting an out-of-bounds page (e.g., page 3 when only 2 pages exist), paginated can also be nil

The code then calls paginated.group_by(&:date) without checking for nil, causing the error.

Changes

  1. Added early return [{}, nil] when no events exist to avoid unnecessary pagination
  2. Added paginated ||= [] guard clause to handle edge cases where paginated is nil even with events

Testing

  • Added spec/controllers/events_controller_spec.rb with tests for empty events edge case
  • All existing tests continue to pass

Rollbar Reference

https://app.rollbar.com/a/codebar-production/fix/item/codebar-production/669#detail

@mroderick mroderick marked this pull request as ready for review April 22, 2026 17:54
@mroderick mroderick merged commit 98df674 into codebar:master Apr 23, 2026
8 checks passed
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