Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError when trying to bundle exec flipper list #917

Open
ola-noblesquad opened this issue Mar 7, 2025 · 3 comments
Open

NoMethodError when trying to bundle exec flipper list #917

ola-noblesquad opened this issue Mar 7, 2025 · 3 comments

Comments

@ola-noblesquad
Copy link

ola-noblesquad commented Mar 7, 2025

Issue

bin/bundle exec flipper list throws an exception instead of listing gates.

Repro steps:

  1. use ruby 3.2.5
  2. install rails 8.0.1 gem
  3. create an empty rails app
  4. add and install flipper, flipper-active_record, flipper-ui gems
  5. generate models and setup
  6. migrate
  7. attempt to list flipper flags via bin/bundle exec flipper list

Expected

An empty list of flags

Actual

undefined method `column_for_attribute' for Flipper::Gate:Class (NoMethodError) exception in flipper/adapters/active_record.rb:292:in `value_not_text?'

See below terminal commands for detailed repro and stack trace:

flipper-test % rbenv local 3.2.5 
flipper-test % gem install rails -v 8.0.1
flipper-test % rails new .               
flipper-test % echo 'gem "flipper"' >> Gemfile
flipper-test % echo 'gem "flipper-active_record"' >> Gemfile
flipper-test % echo 'gem "flipper-ui '~1.2"' >> Gemfile           
flipper-test % bin/bundle install
flipper-test % bin/rails g flipper:active_record flipper:setup
flipper-test % bin/rake db:migrate
flipper-test % bin/bundle exec flipper list
bundler: failed to load command: flipper (.rbenv/versions/3.2.5/bin/flipper)
.rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-active_record-1.3.4/lib/flipper/adapters/active_record.rb:292:in `value_not_text?': undefined method `column_for_attribute' for Flipper::Gate:Class (NoMethodError)

        @gate_class.column_for_attribute(:value).type != :text
                   ^^^^^^^^^^^^^^^^^^^^^
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-active_record-1.3.4/lib/flipper/adapters/active_record.rb:65:in `initialize'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-active_record-1.3.4/lib/flipper/adapters/active_record.rb:306:in `new'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-active_record-1.3.4/lib/flipper/adapters/active_record.rb:306:in `block (2 levels) in <main>'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/adapter_builder.rb:41:in `to_adapter'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/configuration.rb:29:in `adapter'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/engine.rb:55:in `block (3 levels) in <class:Engine>'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/configuration.rb:65:in `default'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper.rb:46:in `instance'
	from .rbenv/versions/3.2.5/lib/ruby/3.2.0/forwardable.rb:234:in `features'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/cli.rb:76:in `block (2 levels) in initialize'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/cli.rb:255:in `run'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/cli.rb:123:in `run'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/lib/flipper/cli.rb:6:in `run'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/flipper-1.3.4/exe/flipper:5:in `<top (required)>'
	from .rbenv/versions/3.2.5/bin/flipper:25:in `load'
	from .rbenv/versions/3.2.5/bin/flipper:25:in `<top (required)>'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `load'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:23:in `run'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli.rb:455:in `exec'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli.rb:35:in `dispatch'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/cli.rb:29:in `start'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/exe/bundle:28:in `block in <top (required)>'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from .rbenv/versions/3.2.5/lib/ruby/gems/3.2.0/gems/bundler-2.5.17/exe/bundle:20:in `<top (required)>'
	from bin/bundle:108:in `load'
	from bin/bundle:108:in `<main>'

It also repros with the latest released version of flipper in rails 7 and ruby 3.1:

rbenv local 3.1.6
gem install rails
rails new .
echo 'gem "flipper"' >> Gemfile
echo 'gem "flipper-active_record"' >> Gemfile
echo 'gem "flipper-ui"' >> Gemfile
bin/bundle install
bin/rails g flipper:active_record flipper:setup
bin/rake db:migrate
bin/bundle exec flipper list

produces the same exception.

Going back to flipper 1.3.0 does not. With this in the Gemfile:

gem "flipper", "=1.3.0"
gem "flipper-ui"
gem "flipper-active_record"

bin/bundle exec flipper list does not throw an exception.

@ola-noblesquad
Copy link
Author

I tested and then updated the description that up through 1.3.0 works on rails 7, but not rails 8 (maybe obviously?).

@ola-noblesquad
Copy link
Author

This is caused because ActiveRecord::Base isn't actually loaded yet, so the ActiveSupport.on_load(:active_record) callback hasn't happened so none of the active record methods are available to the @gate_class when value_not_text? is called.

From a user perspective, the solution is to do something with activerecord in the initializer to force the load. I added this to my flipper initializer:

Rails.application.configure do
  config.after_initialize { ::ActiveRecord::Base.respond_to?(:retrieve_connection) }
end

and now everything works as expected.

@brendo
Copy link

brendo commented Mar 11, 2025

Can reproduce, and the fix stated in #917 (comment) also worked in my scenario.

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

No branches or pull requests

2 participants