Following both @mmoll work on Rails 5.2.1 (and my own ), I came a cross several subjects that should be taken in considerations for plugins .
Background:
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.
Status
- Core PR opened
-
Katello
- 5.2 branch tests are passing
- db setup issue PR merged
- additional fixes (issues to be filed) PR merged
-
ERROR: cached plan must not change result type
when running against core PR merged
-
Foreman-tasks
- - 5.2 branch tests are passing (failures unrelated)
- - functionality tested by @iNecas
-
Remote Execution
- - 5.2 branch tests are passing
- - functionality tested by @iNecas
-
Discovery
- - 5.2 branch tests are failing: two additional tests compared to the develop branch: this and this test
- - develop branch tests are faililng
- - functionality not tested
-
Ansible
- - 5.2 branch tests are pending: there is one issue regarding db:setup in connection to register_rex_feature, @iNecas will propose a fix to remote execution
- - opened PR to fix the issue with db:create and RemoteExecutionFeature
- - develop branch tests are passing
- - functionality not tested
-
Bootdisk
- - 5.2 branch tests are pending - the migration is failling due to use of ActiveRecord::Migrator
- - develop branch tests are failing - 7 known failures in the develop branch (failures unrelated)
- - functionality not tested
-
OpenSCAP
-
- 5.2 branch tests are pending - tests failures due to using class in
class_name
option - - a PR to fix class_name issue opened
- - develop branch tests are passing (failures unrelated)
- - functionality not tested
-
- 5.2 branch tests are pending - tests failures due to using class in
-
Templates
- - 5.2 branch tests are pasing (failures unrelated)
- - develop branch tests are passing
- - functionality not tested
-
Hooks
- - 5.2 branch tests are pending (failures unrelated)
- - develop branch tests are passing
- - functionality not tested
-
Packaging
- build 5.2 scl packages
- Update Rails SCL to 5.2.1
- Test build Foreman and Katello packaging locally with code changes prior to merge
Who should read this?
Everyone or just plugin writers, that works too
Migrations
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.