Closed ekohl closed 7 months ago
How to reproduce:
:red_circle: Without Ansible:
# bundler.d/dev.rb
gem 'foreman_leapp', path: '/path/gem'
bundle exec rails db:migrate
bundle exec rails db:seed ==> fails
:green_circle: With Ansible:
# bundler.d/dev.rb
gem 'foreman_ansible', path: '/path/gem'
gem 'foreman_leapp', path: '/path/gem'
bundle exec rails db:migrate
bundle exec rails db:seed ==> works
Not sure why it's happening, ansible is set as dependency, need to investigate closer ..
Oh, that is interesting. I can confirm that bundle show
does list foreman_ansible
:
$ bundle info foreman_ansible
* foreman_ansible (10.1.0)
So it's also not pulling in an ancient version.
Yet, when I add it to bundler it does load. That makes me think this code could be related: https://github.com/theforeman/foreman/blob/34728aee6b213c68e56df7bb5e3b86ab194b2a33/config/application.rb#L29-L66
My theory is that bundler doesn't know to load the gem, somehow. If you list a gem in a Gemfile
then there's an implicit require. I suspect that you can reproduce this by adding this:
gem 'foreman_ansible', require: false
We have this code in Foreman to declare a dependency as well: https://github.com/theforeman/foreman/blob/6575dc039092bcb2bf5c9e2bc45139cb16f6e26e/app/registries/foreman/plugin.rb#L236-L248
Yet, I doubt its usefulness in the current form. One issue is the load order. If you first load foreman_leapp
and then foreman_ansible
the Plugin.find('foreman_ansible')
code would fail.
Historical explanation why it makes sense to check the version: we have bundler_ext that discards the version checks that bundler does. However, we now also enforce the same dependencies via RPMs so that doesn't really make sense anymore.
But something like this could be a path to ensure the dependency is actually loaded. The version matcher should be made optional (and deprecated) while also adding support for declaring an optional dependency.
I've started hitting this in https://github.com/theforeman/foreman_leapp/pull/133 too
When trying to seed on a fresh installation I get: