Skip to content

Use model.arel_table in ActiveRecord get_all for Rails main compatibility#1003

Open
kylekeesling wants to merge 1 commit into
flippercloud:mainfrom
kylekeesling:fix-arel-table-keyword-arg
Open

Use model.arel_table in ActiveRecord get_all for Rails main compatibility#1003
kylekeesling wants to merge 1 commit into
flippercloud:mainfrom
kylekeesling:fix-arel-table-keyword-arg

Conversation

@kylekeesling

Copy link
Copy Markdown

Problem

Flipper::Adapters::ActiveRecord#get_all builds its join query with positional Arel::Table.new calls:

features = ::Arel::Table.new(@feature_class.table_name.to_sym)
gates    = ::Arel::Table.new(@gate_class.table_name.to_sym)

Rails main reworked Arel::Table to be keyword-only (rails/rails#57021def initialize(name: nil, as: nil, klass: nil, ...)). The positional call now raises:

ArgumentError: wrong number of arguments (given 1, expected 0)

Because Flipper::Middleware::Memoizer calls preload_allget_all on every request, this breaks every request (including health-check endpoints) on any app tracking Rails main / edge. We hit this in production when our Rails-main pin moved past that commit.

Fix

Use ActiveRecord::Base.arel_table instead. It returns the same table, is maintained by Rails, and has existed since Rails 4 — so it sidesteps the constructor signature entirely and works across the full supported matrix (5.2–8.0) and Rails main.

features = @feature_class.arel_table
gates    = @gate_class.arel_table

Testing

  • bundle exec rspec spec/flipper/adapters/active_record_spec.rb (sqlite): 52 examples, 0 failures (the 2 pending are pre-existing sqlite role limitations).
  • Verified downstream against Rails main: reproduced the ArgumentError, confirmed the change makes Flipper.preload_all succeed.

CI's matrix doesn't currently include Rails main, so this regression isn't caught upstream — happy to add a rails: main matrix entry in a follow-up if useful.

Rails main (rails/rails#57021) makes Arel::Table.new keyword-only, so the
positional Arel::Table.new(table_name.to_sym) calls in get_all raise
ArgumentError: wrong number of arguments (given 1, expected 0). Because the
memoizer middleware calls preload_all on every request, this breaks every
request on apps tracking Rails main.

ActiveRecord::Base.arel_table returns the same table and is stable across all
supported Rails versions (5.2-8.0 and main), so it avoids the constructor
signature entirely.
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.

1 participant