What you should know regarding Rails 5.2.0 and Foreman

Following both @mmoll work on Rails 5.2.1 (and my own :wink:), I came a cross several subjects that should be taken in considerations for plugins .

Rails 5.2.1 (please do not be confused with Rails 5.2.x above 5.2.1) made several changes and bug fixes for both ActiveModel and ActiveRecord that affected Foreman and Katello.

While there are many changes to that version of Rails, it didn’t affected that much Foreman or Katello, so the following thread is about what was affecting it, and how to solve it.


Who should read this?
Everyone :wink: or just plugin writers, that works too :stuck_out_tongue:

First thing that was changed are migrations.

ActiveRecord::Migrator.get_all_versions.include? was replaced with ActiveRecord::Base.connection.migration_context.get_all_versions.include?.

Callback hooks
There are two main callback hooks that we are using on Foreman:
before_save and after_save.

On Rails 5.1 there was a preparation for the following changes, and two duck typed methods were introduced:

  • XXX_previously_changed?
  • XXX_before_last_save

For example title_previously_changed? will be true if the value was changed and then saved, and title_before_last_save will exists after saving was made, and holds the previous value of title field.

The following changes started to be clearer in Rails 5.2.0. The before_save have access to _changed? and _was methods, but after_save the _changed? method will always return false, and the _was method will always return the current value.

The new two methods holds the changes that existed prior to the saving.
The older methods holds the current state of a field prior for saving,

Lack of proper handling for this changes will break code and tests, or just return nil or wrong value, so please look for the after_save and change the code to support the new methods if needed.

has_many :class_name option

Rails 5.2 requires :class_name option of the has_many method to be always string. We’ve seen this issue in Foreman_openscap plugin.

An important thing to note is that we are planning to upgrade Foreman core to Rails 5.2 around early September, to ensure plugins have enough time to adapt to the breaking changes and that nightlies are stable in time for 1.20 branching.
@ik5 - Which of these changes are backward-compatible with 5.1 and which can only be done after the upgrade to 5.2?

Is there a replacement method or do we need to figure it out without these methods being available?

Do you have some example PRs where we can simply copy&paste solution? :slight_smile:

it’s based on the issue at hand, but they are available, duck typing is your friend

Sorry, what? I don’t understand. Which reminds me.

What’s that? I know duck typing, but this term is new to me.

I’ll add some update information around the packaging effort that is required as well. This is strictly RPM based since Debian uses gems more directly and thus does not require building an SCL.

The previously named tfm-ror51-packaging repository has been renamed to rails-packaging and the default branch set to tfm-ror52. The set of packages available currently matches all previously required packages. A test repository of just the Rails 5.2 SCL can be found here.

The current status is that of test building all of Foreman packages against this new SCL and making updates to existing packaging where possible ahead of time. Thus far the amount of required changes has been minimal. The packaging effort should align well with the target dates.

Also note that with this upgrade to Rails 5.2 comes an update to Ruby 2.5 for RPM based deployments.

1 Like

I’ve added a ‘status’ section in the original post, describing where we are with the upgrade currently. I’ve added links to jenkins jobs running against the 5.2 branch, as well as control job with running plugins against foreman develop, so that we can eliminate the issues that are already present in the plugins and are unrelated to the Rails 5.2 change.

Any help with functional testing of the plugins is welcome. Also, please feel free to add more plugins you with to check and track here. It probably doens’t mean we would block the whole upgrade before fixing those, but it’s good to have an generic awareness about what plugins are affected.

Both tasks and remote execution required no change for the Rails 5.2 upgrade.

I updated the packaging status to capture the two tasks I am going to work on leading up to core code merge:

  • Updating Rails SCL to 5.2.1
  • Pre-build testing the core code change locally

Considering the current state of the upgrade, I suggest aiming for next Thursday for merging the core change - which will break any incompatible plugins. I agree with @iNecas that we should not block the core upgrade until all plugins are ready. If noone objects by tomorrow afternoon my time, I will post a second thread to make sure plugin maintainers are aware of this and have a week to prepare.

Also, I’m not sure why the original post talks about 5.2.0 and explicitly excludes 5.2.1. Considering that 5.2.1 has been out for a few weeks already, and as far as I can tell from the changelogs does not contain any breaking changes, I suggest we go straight to 5.2.1.

Packaging Update:

  • Some Katello Ruby 2.5 errors were identified during building
  • They are fixed in this PR
  • rubygem-katello built successfully after applying the Rails 5.2 and Ruby 2.5 patches

A quick note for people handling the upgrade in plugins:
The behavior of $ATTR_previously_changed? in after_* callbacks changed between 5.1 and 5.2. In case you use this function and want to fix it to work with both versions, use the saved_change_to_attribute?(:$ATTR) method instead which behaves the same in both versions.

This has now been merged in Foreman core. We expect some instability with nightlies until all SCL issues are sorted out. Please make sure your plugins continue to function after the upgrade and reach out if you need any assistance updating them.


While trying to build foreman_openscap I hit an error that looks code related. Is this a known issue with foreman_openscap and Rails 5.2?

[1] http://koji.katello.org/kojifiles/work/tasks/8215/128215/build.log

Check that, I found – https://github.com/theforeman/foreman-packaging/pull/2932 which passed.