theforeman / foreman_leapp

GNU General Public License v3.0
0 stars 15 forks source link

ActiveRecord::RecordInvalid: Validation failed: Provider type translation missing: en.activerecord.errors.models.job_template.attributes.provider_type.uniq #120

Closed ekohl closed 7 months ago

ekohl commented 1 year ago

When trying to seed on a fresh installation I get:

ActiveRecord::RecordInvalid: Validation failed: Provider type translation missing: en.activerecord.errors.models.job_template.attributes.provider_type.uniq
/home/ekohl/dev/foreman_leapp/db/seeds.d/10_leapp_preupgrade.rb:18:in `block (4 levels) in <main>'
stejskalleos commented 1 year 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 ..

ekohl commented 1 year ago

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

ekohl commented 8 months ago

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.

evgeni commented 7 months ago

I've started hitting this in https://github.com/theforeman/foreman_leapp/pull/133 too