Replies: 4 comments
-
Hey @offbyone, this is indeed intentional. Each adapter will configure itself as the default when it is loaded. If your app is loading more than one adapter, I would recommend being explicit about which one you want to use: # config/initializers/flipper.rb
require "flipper/adapters/pstore"
require "flipper-active_record"
Flipper.configure do |config|
config.adapter { Flipper::Adapters::ActiveRecord.new }
end
We thought it was worth the tradeoff to make it "just work". I'd love to hear a counter-argument. |
Beta Was this translation helpful? Give feedback.
-
One reason it’s not so great is that the act of importing the pstore adapter creates a config file in the current working directories, despite the fact that I intend to provide it with a different file. Edit: Okay, so I'm on an actual keyboard now and I can use words better :D I hope the response above explains at least the initial issue; if your default adapter has side effects like file creation, you will get those before you even have the option of configuring them; if they need a network connection, same problem. That'll happen no matter when you do it; you can be trying to bootstrap them in the rails initializer (which I'm now doing, in a careful order) and now no matter what I do I will always have a I don't think that automatic configuration like this is particularly friendly, tbh; certainly the two days I spent trying to figure out why at random times in my Rails app's lifetime the feature flag provider would change from our actual ActiveRecord one to one configured off of an empty pstore file, sometimes in response to someone else other than me interacting with it was not my favorite experience. Give me control over when things are initialized, please. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation. I really appreciate you taking time to give feedback.
Let me know if this is not the behavior you are seeing, but the PStore file should not be initialized until the first time the adapter is accessed (by calling # config/initializers/flipper.rb
require "flipper/adapters/pstore"
Flipper.configure do |config|
config.adapter { Flipper::Adapters::PStore.new("path/to/different/flipper.pstore") }
end See details from `rails console` session to confirm
Really sorry about that. I hate when you're fighting with something for days and it turns out to be something hidden. We will make it explicit in the docs that loading an adapter makes it the default. At this point we can't remove the automatic configuration because it will cause unexpected failures for other people. We could look into raising a warning or error if multiple adapters are loaded without explicit configuration.
You definitely have control and are encouraged to explicitly configure flipper (see example in my first comment here) if you're doing anything advanced. |
Beta Was this translation helpful? Give feedback.
-
I don't, though! I was dynamically loading the Flipper PStore adapter in a library that was syncing state from activerecord to pstore. Logically, there was no reason to import the pstore adapter anywhere else -- it was used only in that method -- so importing it there, close to the code, made sense... except the part where just importing the code in order to configure it resulted in the reconfiguration of my entire application. I've found a workaround, so I'm not blocked here, but consider in the future not having system-level side effects when importing code. All hyperbole aside, that's not a developer-friendly practice. |
Beta Was this translation helpful? Give feedback.
-
When I require a
pstore
adapter in a library in my rails app that isn't loaded automatically at engine initialization, the three lines at the bottom are replacing the global instance adapter with the newly loaded adapter. That's sort of counter-intuitive.Is this intentional behaviour? If it is, then how do I require
flipper/adapters/pstore
without changing my global adapter?Beta Was this translation helpful? Give feedback.
All reactions