flippercloud / flipper

🐬 Beautiful, performant feature flags for Ruby.
https://www.flippercloud.io/docs
MIT License
3.71k stars 418 forks source link

undefined method `column_for_attribute' for class Flipper::Gate #884

Open bibendi opened 1 month ago

bibendi commented 1 month ago

Hey!

I got an error after I upgraded flipper-active_record from v1.3.0 to v1.3.1

/usr/local/bundle/gems/flipper-active_record-1.3.1/lib/flipper/adapters/active_record.rb:292:in `value_not_text?': undefined method `column_for_attribute' for class Flipper::Gate (NoMethodError)

        @gate_class.column_for_attribute(:value).type != :text
                   ^^^^^^^^^^^^^^^^^^^^^
    from /usr/local/bundle/gems/flipper-active_record-1.3.1/lib/flipper/adapters/active_record.rb:65:in `initialize'
    from /app/config/initializers/flipper.rb:12:in `new'
    from /app/config/initializers/flipper.rb:12:in `block in <top (required)>'
    from /usr/local/bundle/gems/flipper-1.3.1/lib/flipper.rb:24:in `configure'
    from /app/config/initializers/flipper.rb:10:in `<top (required)>'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:690:in `load'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:690:in `block in load_config_initializer'
    from /usr/local/bundle/gems/activesupport-7.1.3.4/lib/active_support/notifications.rb:208:in `instrument'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:689:in `load_config_initializer'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:643:in `block (2 levels) in <class:Engine>'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:642:in `each'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/engine.rb:642:in `block in <class:Engine>'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:32:in `instance_exec'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:32:in `run'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:425:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:424:in `block in each_strongly_connected_component_from'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:50:in `each'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:50:in `tsort_each_child'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:418:in `call'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:418:in `each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:350:in `each'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:350:in `call'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
    from /usr/local/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/initializable.rb:60:in `run_initializers'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/application.rb:426:in `initialize!'
    from /app/config/environment.rb:5:in `<top (required)>'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /usr/local/bundle/gems/zeitwerk-2.6.15/lib/zeitwerk/kernel.rb:34:in `require'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/application.rb:402:in `require_environment!'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command/actions.rb:20:in `boot_application!'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/commands/console/console_command.rb:105:in `perform'
    from /usr/local/bundle/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /usr/local/bundle/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command/base.rb:178:in `invoke_command'
    from /usr/local/bundle/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command/base.rb:73:in `perform'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command.rb:71:in `block in invoke'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command.rb:149:in `with_argv'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/command.rb:69:in `invoke'
    from /usr/local/bundle/gems/railties-7.1.3.4/lib/rails/commands.rb:18:in `<top (required)>'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from bin/rails:4:in `<main>'
bibendi commented 1 month ago

config/initializers/flipper.rb

# frozen_string_literal: true

require "active_support/cache"
require "flipper/adapters/active_record"
require "flipper/adapters/active_support_cache_store"
require "flipper/adapters/redis_cache"

FLIPPER_ID_STRUCT = Struct.new(:flipper_id)

Flipper.configure do |config|
  redis_adapter = Flipper::Adapters::RedisCache.new(
    Flipper::Adapters::ActiveRecord.new,
    PRIMARY_REDIS,
    900 # ttl in seconds - 15 minutes
  )

  config.adapter do
    Flipper::Adapters::ActiveSupportCacheStore.new(
      redis_adapter,
      ActiveSupport::Cache::MemoryStore.new,
      1.minute
    )
  end
end
danielmorrison commented 1 month ago

Looks like this was a side-effect of #832.

In you initializer you can wrap things in

ActiveSupport.on_load(:active_record) do
   # flipper config here
end

Not sure if there's a better callback to hook into, but that got me working.