Skip to content

Retire RegistrationPolicyBucket#key as an identity mechanism in the app layer (phase 3 of dropping RegistrationPolicyBucket#key) #11897

Description

@nbudin

Background

#11895 and #11896 remove every external (frontend, GraphQL, Liquid) dependency on RegistrationPolicyBucket#key as identity. This issue is the remaining internal app-layer cleanup needed before the column itself can be dropped (#11898): the handful of places that still fall back to key-based matching specifically because the frontend didn't supply bucket ids -- which, after #11895, it now reliably does.

  • RegistrationPolicy#sync_buckets_from_hash!/#match_existing_bucket (app/models/registration_policy.rb): still falls back to existing_by_key when an incoming bucket hash has no id. Once every caller that edits an existing registration policy reliably supplies id for any bucket that already exists, this fallback is no longer reachable in practice and can be removed -- but it needs to be deleted, not just left dead, so a hash with no id is unambiguously "this is a brand new bucket" rather than "maybe this secretly matches something by key."
  • RegistrationPolicy#equivalent_to?: currently matches self's buckets against other's by key (other.buckets.find { |b| b.key == bucket.key } -- added in Convert remaining registration policy bucket key dependencies (SignupBucketFinder, EventChangeRegistrationPolicyService) to id #11892, with a comment explaining it's structurally needed for now). Once other (typically a detached policy from build_from_hash) reliably carries ids for anything pre-existing, this should match by id instead, with a bucket that has no id always counting as "different" (correct: a brand-new bucket, by definition, changes the policy).
  • EventChangeRegistrationPolicyService::SignupSimulator#candidate_bucket_for (app/services/event_change_registration_policy_service.rb): the one remaining commented key-based bridge from Convert remaining registration policy bucket key dependencies (SignupBucketFinder, EventChangeRegistrationPolicyService) to id #11892, translating a real signup's persisted bucket into its detached candidate counterpart during simulation. Same fix: id-based lookup for anything that already existed pre-edit; a genuinely brand-new bucket in the same edit has no id at this point and so has no "current"/"requested" candidate to bridge to at all (correct -- a signup can't already be sitting in, or have already requested, a bucket that didn't exist yet).

Before removing the sync_buckets_from_hash! fallback, audit the other callers of RegistrationPolicy.build_from_hash/#update_from! beyond the updateEvent mutation path that #11895 fixes, to confirm each one either (a) never has pre-existing buckets to match against (a brand-new policy/record, so the fallback was never load-bearing there), or (b) needs its own id-plumbing fix first:

Proposed Change

  1. Remove RegistrationPolicy#sync_buckets_from_hash!'s existing_by_key fallback (after confirming the caller audit above).
  2. Switch RegistrationPolicy#equivalent_to? to id-based matching.
  3. Switch EventChangeRegistrationPolicyService::SignupSimulator#candidate_bucket_for to an id-based lookup.
  4. Update or remove the comments in RegistrationPolicy#build_from_hash/#sync_buckets_from_hash!/RegistrationPolicyBucket#occupies_bucket_as_signup? that describe the key-based fallback, since it will no longer exist.

Benefits

Tradeoffs

References


Issue drafted by Claude

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions