Skip to content

Fix members#new 500 from nil MembershipPricing amounts - #180

Merged
thibaudgg merged 1 commit into
masterfrom
cursor/membership-pricing-nil-round-bb3e
Sep 15, 2026
Merged

thibaudgg merged 1 commit into
masterfrom
cursor/membership-pricing-nil-round-bb3e

Conversation

@thibaudgg

Copy link
Copy Markdown
Member

Fixes a recurring production 500 on the public member registration form when the live pricing turbo-frame refreshes.

AppSignal

  • Incident: CSA Admin / production exception #347
  • Exception: ActionView::Template::Error wrapping undefined method 'round_to_five_cents' for nil
  • Action: Members::MembersController#new (GET /new)
  • Latest failing tenant: seminterra
  • First seen 2024-12-03; still open and last seen 2026-09-15

App frames:

  • app/models/membership_pricing.rb #add / #prices / #present?
  • app/views/members/members/_pricing.html.erb:3
  • app/views/members/members/new.html.erb:95-97

Root cause

The pricing partial builds MembershipPricing from the registration form params (turbo-frame refresh on GET /new).

The latest failing request had:

  • waiting_basket_size_id set
  • waiting_basket_price_extra set (1.0)
  • waiting_activity_participations_demanded_annually set (10)
  • waiting_depot_id set
  • waiting_delivery_cycle_id blank

#activity_participations_prices maps over resolved delivery cycles and returns [counts.min, counts.max]. When no cycle can be resolved (blank cycle id and a depot without kept cycles, or no depot/cycles at all), that map is empty and the method returns [nil, nil]. #add then calls round_to_five_cents on nil and the pricing frame 500s.

This is not a missing basket/depot fee column. Those prices are non-null. The nil is the computed activity-participation price range when there is no delivery-cycle context.

Fix

  • Return [0, 0] for activity (and complement) prices when no delivery cycle can be resolved, instead of [nil, nil].
  • Treat a nil amount as 0 before rounding, so #add cannot 500.
  • Skip extra-price math when the delivery count is zero, so the same incomplete form state cannot divide by zero.

Valid form data with a resolvable cycle is unchanged (existing pricing tests still pass). An incomplete selection now shows no price rather than a 500.

Tests

test/models/membership_pricing_test.rb covers the production-like params (activity + extra + selected depot + blank cycle, depot with no cycles) and the no-depot/no-cycle case.

Do not merge, deploy, or close the AppSignal incident from this PR.

Open in Web Open in Cursor 

MembershipPricing#add called round_to_five_cents on nil when the
registration form asked for activity participations but no delivery
cycle could be resolved. Treat missing price parts as zero and skip
activity/extra math without a cycle or delivery count.

Co-authored-by: Thibaud Guillaume-Gentil <thibaud@thibaud.gg>
@thibaudgg
thibaudgg force-pushed the cursor/membership-pricing-nil-round-bb3e branch from 30001db to 9def02f Compare September 15, 2026 15:59
@thibaudgg
thibaudgg marked this pull request as ready for review September 15, 2026 16:00
@thibaudgg
thibaudgg merged commit a58e702 into master Sep 15, 2026
3 checks passed
@thibaudgg
thibaudgg deleted the cursor/membership-pricing-nil-round-bb3e branch September 15, 2026 16:00
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