Use model.arel_table in ActiveRecord get_all for Rails main compatibility#1003
Open
kylekeesling wants to merge 1 commit into
Open
Use model.arel_table in ActiveRecord get_all for Rails main compatibility#1003kylekeesling wants to merge 1 commit into
kylekeesling wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Flipper::Adapters::ActiveRecord#get_allbuilds its join query with positionalArel::Table.newcalls:Rails main reworked
Arel::Tableto be keyword-only (rails/rails#57021 —def initialize(name: nil, as: nil, klass: nil, ...)). The positional call now raises:Because
Flipper::Middleware::Memoizercallspreload_all→get_allon 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_tableinstead. 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.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).ArgumentError, confirmed the change makesFlipper.preload_allsucceed.CI's matrix doesn't currently include Rails main, so this regression isn't caught upstream — happy to add a
rails: mainmatrix entry in a follow-up if useful.